-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployCommands.js
46 lines (40 loc) · 1.24 KB
/
deployCommands.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
// adapted from https://discordjs.guide/creating-your-bot/command-deployment.html#guild-commands
const { REST, Routes } = require('discord.js');
const { db } = require('./db');
const { plugins } = require('./config');
const allServers = false;
const commands = [];
for (const p of plugins) {
const plugin = require(p);
if (plugin.commands) {
plugin.commands.forEach((command) => {
commands.push(command.data.toJSON());
});
}
}
// and deploy your commands!
(async () => {
try {
const { settings } = await db.get();
// Construct and prepare an instance of the REST module
console.log(
`Started refreshing ${commands.length} application (/) commands.`
);
// The put method is used to fully refresh all commands in the guild with the current set
const rest = new REST().setToken(settings.discord.token);
const data = await rest.put(
allServers
? Routes.applicationCommands(settings.discord.client_id)
: Routes.applicationGuildCommands(
settings.discord.client_id,
settings.devServer
),
{ body: commands }
);
console.log(
`Successfully reloaded ${data.length} application (/) commands.`
);
} finally {
db.release();
}
})();