-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-commands.js
43 lines (35 loc) · 1.42 KB
/
deploy-commands.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
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const commandList = [];
fs.readdirSync('./commands/').forEach(dirs => {
const commands = fs.readdirSync(`./commands/${dirs}`).filter(files => files.endsWith('.js'));
for (const file of commands) {
const command = require(`./commands/${dirs}/${file}`);
commandList.push(command.data.toJSON());
delete require.cache[require.resolve(`./commands/${dirs}/${file}`)];
};
});
// Construct and prepare an instance of the REST module
const rest = new REST({ version: '10' }).setToken(token);
// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commandList.length} application (/) commands.`);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commandList },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
console.log(`Started refreshing ${data.length} global application (/) commands.`);
await rest.put(
Routes.applicationCommands(clientId),
{ body: commandList },
);
console.log(`Successfully reloaded ${data.length} global application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();