-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy-commands.js
41 lines (38 loc) · 1.19 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
const fs = require('fs');
const { Collection, REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const Logger = require('./services/logger');
// Commands
const commandFiles = fs.readdirSync('./commands').filter((file) => file.endsWith('.js'));
const commands = new Collection();
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
// filter only files with .data
if (!('data' in command)) {
continue;
}
// compute slash command data (using config)
if (typeof command.computeData === 'function') {
command.computeData();
}
// add to the list
commands.set(command.name, command);
}
if (commands.size === 0) {
Logger.info('No application command to save.');
process.exit();
}
// Create or update commands
const commandsData = commands.map((command) => command.data.toJSON());
const rest = new REST({ version: '10' }).setToken(token);
// Deploy commands
(async () => {
try {
await rest.put(Routes.applicationGuildCommands(clientId, guildId), {
body: commandsData,
});
Logger.info('Successfully registered application commands.');
} catch (error) {
Logger.error(error);
}
})();