forked from NGIT-Open-Source/Neil.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-commands.js
37 lines (30 loc) · 1.24 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
// Run `node deploy-commands.js` whenever you add a new command
// Failing to do so, New commands can't be registered and accessed on Discord
// Please refer https://discordjs.guide/creating-your-bot/creating-commands.html
require('dotenv').config();
const fs = require('fs');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { clientId, guildId, token } = process.env;
// The below script is setup in such a way that developers don't need to add New commands here manually,
// Commands will be grabbed from commands/your-command.js directly if you follow the correct methods to create a new command
const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '9' }).setToken(token);
(async () => {
try {
console.log('Started refreshing🔄 application Slash(/) commands.');
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log('Successfully reloaded✅ application Slash(/) commands.');
}
catch (error) {
console.error(error);
}
})();