-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-commands.js
52 lines (40 loc) · 1.61 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
44
45
46
47
48
49
50
51
52
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const commands = [];
// Grab all the command files from the commands directory you created earlier
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
}
const rest = new REST().setToken(token);
//del commands
// for guild-based commands
//rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: [] })
// .then(() => console.log('Successfully deleted all guild commands.'))
// .catch(console.error);
// for global commands
rest.put(Routes.applicationCommands(clientId), { body: [] })
.then(() => console.log('Successfully deleted all application commands.'))
.catch(console.error);
// deploy commands globally
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
const data = await rest.put(
//this was for guild-based commands - i dont use that here, but could be used
//Routes.applicationGuildCommands(clientId, guildId),
//route for global commands
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
} finally {
// This will ensure that the script ends after the asynchronous operations are completed
process.exit();
}
})();