forked from StormPacer/yatb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
122 lines (98 loc) · 3.56 KB
/
bot.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const fs = require("fs");
const { Client, Collection, GatewayIntentBits, Partials } = require("discord.js");
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
require("dotenv").config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
partials: [Partials.Channel],
});
const eventFiles = fs
.readdirSync("./events")
.filter((file) => file.endsWith(".js"));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(
event.name,
async (...args) => await event.execute(...args, client)
);
}
}
client.slashCommands = new Collection();
client.buttonCommands = new Collection();
client.selectCommands = new Collection();
client.modalCommands = new Collection();
client.autocompleteInteractions = new Collection();
const slashCommands = fs.readdirSync("./interactions/slash");
for (const module of slashCommands) {
const commandFiles = fs
.readdirSync(`./interactions/slash/${module}`)
.filter((file) => file.endsWith(".js"));
for (const commandFile of commandFiles) {
const command = require(`./interactions/slash/${module}/${commandFile}`);
client.slashCommands.set(command.data.name, command);
}
}
const autocompleteInteractions = fs.readdirSync("./interactions/autocomplete");
for (const module of autocompleteInteractions) {
const files = fs
.readdirSync(`./interactions/autocomplete/${module}`)
.filter((file) => file.endsWith(".js"));
for (const interactionFile of files) {
const interaction = require(`./interactions/autocomplete/${module}/${interactionFile}`);
client.autocompleteInteractions.set(interaction.name, interaction);
}
}
const buttonCommands = fs.readdirSync("./interactions/buttons");
for (const module of buttonCommands) {
const commandFiles = fs
.readdirSync(`./interactions/buttons/${module}`)
.filter((file) => file.endsWith(".js"));
for (const commandFile of commandFiles) {
const command = require(`./interactions/buttons/${module}/${commandFile}`);
client.buttonCommands.set(command.id, command);
}
}
const modalCommands = fs.readdirSync("./interactions/modals");
for (const module of modalCommands) {
const commandFiles = fs
.readdirSync(`./interactions/modals/${module}`)
.filter((file) => file.endsWith(".js"));
for (const commandFile of commandFiles) {
const command = require(`./interactions/modals/${module}/${commandFile}`);
client.modalCommands.set(command.id, command);
}
}
const selectMenus = fs.readdirSync("./interactions/select-menus");
for (const module of selectMenus) {
const commandFiles = fs
.readdirSync(`./interactions/select-menus/${module}`)
.filter((file) => file.endsWith(".js"));
for (const commandFile of commandFiles) {
const command = require(`./interactions/select-menus/${module}/${commandFile}`);
client.selectCommands.set(command.id, command);
}
}
const rest = new REST({ version: "9" }).setToken(process.env.TOKEN);
const commandJsonData = [...Array.from(client.slashCommands.values()).map((c) => c.data.toJSON())];
(async () => {
try {
console.log("Started refreshing application (/) commands.");
await rest.put(
Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.GUILD_ID),
{ body: commandJsonData }
);
console.log("Successfully reloaded application (/) commands.");
} catch (error) {
console.error(error);
}
})();
client.login(process.env.TOKEN);