-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy-commands.js
44 lines (37 loc) · 1.47 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
const fs = require('fs');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const config = require('./config.json');
require('dotenv').config();
const runtime = process.env.RUNTIME || 'development';
const rest = new REST({ version: '9' }).setToken(config.token);
const commands = {
guild: [],
global: [],
};
for (const commandFolderScope of fs.readdirSync('./commands')) {
const commandFiles = fs.readdirSync(`./commands/${commandFolderScope}`)
.filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${commandFolderScope}/${file}`);
console.log(`Registering ${commandFolderScope} slash command: ${command.data.name}`);
// only register global commands if we are in production mode
if (commandFolderScope === 'global' && runtime === 'production') {
commands.global.push(command.data.toJSON());
}
else {
commands.guild.push(command.data.toJSON());
}
}
}
rest.put(Routes.applicationGuildCommands(config.clientId, config.managementGuildId), { body: commands.guild })
.then(() => console.log('Registered all Management Guild application commands!'))
.catch(console.error);
if (commands.global.length > 0) {
rest.put(Routes.applicationCommands(config.clientId), { body: commands.global })
.then(() => console.log('Registered all Global commands!'))
.catch(console.error);
}
else {
console.log('No global commands registered...');
}