-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
77 lines (65 loc) · 2.17 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { DISCORD } from "../../config/discord";
import {
Client,
Collection,
Events,
GatewayIntentBits,
Partials,
} from "discord.js";
import MessageCreate from "./events/MessageCreate";
import ClientReady from "./events/ClientReady";
import MessageReactionAdd from "./events/MessageReactionAdd";
import { CommandPromptAsk } from "./commands/ask";
import { CommandPromptHelp } from "./commands/help";
import { CommandPromptTrain } from "./commands/train";
import InteractionCreate from "./events/InteractionCreate";
export default class DiscordBot extends Client {
commands = new Collection();
constructor() {
super({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});
/**
* Login
*/
this.login(DISCORD().token);
/**
* Events
*/
this.once(Events.ClientReady, (client) => ClientReady(client));
this.on(Events.MessageCreate, async (message) =>
MessageCreate({ client: this, message })
);
this.on(Events.MessageReactionAdd, async (reaction, user) =>
MessageReactionAdd({ client: this, reaction, user })
);
this.on(Events.MessageReactionRemove, async (reaction, user) =>
MessageReactionAdd({ client: this, reaction, user })
);
/**
* Commands
*/
this.commands.set(CommandPromptAsk.data.name, CommandPromptAsk);
this.commands.set(CommandPromptHelp.data.name, CommandPromptHelp);
this.commands.set(CommandPromptTrain.data.name, CommandPromptTrain);
// remember also need to add in `registerSlashCommand.ts`
this.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(
`No command matching ${interaction.commandName} was found.`
);
return;
}
InteractionCreate({ client: this, interaction });
});
}
}