-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-commands.mjs
45 lines (37 loc) · 1.39 KB
/
deploy-commands.mjs
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
import { importDir } from './util/importDir.mjs';
import { REST, Routes } from 'discord.js';
import { importJSON } from './util/importJSON.mjs';
import { pkgRelPath } from './util/pkgRelPath.mjs';
const { clientId, guildIds, developmentGuildId, token } = await importJSON(
pkgRelPath('./config.json')
);
// An array of SlashCommandBuilder objects for every command:
const commandData = [];
const developmentCommandData = [];
const commands = await importDir(pkgRelPath('./commands/'));
// For every js file in the commands folder, read its .data property:
for (const command of commands) {
const commandJSON = command.data.toJSON();
if (!command.inDevelopment) {
commandData.push(commandJSON);
}
developmentCommandData.push(commandJSON);
}
const rest = new REST({ version: '9' }).setToken(token);
async function deployCommandsToGuild(guildId, guildCommandData) {
console.log(`Registering application commands for guild ${guildId}...`);
try {
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: guildCommandData }
);
}
catch (GuildCommandError) {
console.error('Failed to deploy commands. Please see this error message:', GuildCommandError);
}
console.log('Successfully registered application commands.');
}
await deployCommandsToGuild(developmentGuildId, developmentCommandData);
for (const guildId of guildIds) {
await deployCommandsToGuild(guildId, commandData);
}