-
Notifications
You must be signed in to change notification settings - Fork 0
/
regCommands.js
49 lines (40 loc) · 1.51 KB
/
regCommands.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
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const config = require('./config.json');
const fs = require('fs');
const rest = new REST({ version: '9' }).setToken(config.token);
const commands = [];
(async () => {
console.log(`Registering commands...`);
var commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"));
for (const file of commandFiles) {
var command = require(`./commands/${file}`);
console.log(`Registering ${command.name}...`);
commands.push(command.command.toJSON());
global.commandsList.set(command.name, command);
}
console.log(`Registering commands... Done!`);
console.log(`Registering routes...`);
const clientID = config.appid;
await rest.put(
Routes.applicationCommands(clientID), {
body: commands
},
);
// For Testing
// rest.get(Routes.applicationGuildCommands(clientID, config.guildid))
// .then(data => {
// const promises = [];
// for (const command of data) {
// const deleteUrl = `${Routes.applicationGuildCommands(clientID, config.guildid)}/${command.id}`;
// promises.push(rest.delete(deleteUrl));
// }
// return Promise.all(promises);
// });
// await rest.put(
// Routes.applicationGuildCommands(clientID, config.guildid), {
// body: commands
// }
// );
console.log(`Registered commands!`);
})();