-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-commands.js
34 lines (28 loc) · 1.25 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
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord.js');
const { clientID, guildID, privateGuildID, token } = require('./settings/config.json');
const fs = require('fs');
let globalCommands = [];
let guildCommands = [];
let privateCommands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
if (command.global === true) globalCommands.push(command.data.toJSON());
else if (command.global === false) guildCommands.push(command.data.toJSON());
else if (command.private) privateCommands.push(command.data.toJSON());
}
const rest = new REST({ version: '10' }).setToken(token);
rest.put(Routes.applicationCommands(clientID), { body: globalCommands })
.then(() => console.log('Successfully registered global commands.'))
.catch(console.error);
rest.put(Routes.applicationGuildCommands(clientID, guildID), {
body: guildCommands,
})
.then(() => console.log('Successfully registered guild commands.'))
.catch(console.error);
rest.put(Routes.applicationGuildCommands(clientID, privateGuildID), {
body: privateCommands,
})
.then(() => console.log('Successfully registered private commands.'))
.catch(console.error);