-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploycommand.mjs
36 lines (24 loc) · 1.07 KB
/
deploycommand.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
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v9';
import { promisify } from 'util';
import glob from 'glob';
import client from './index.mjs';
const globPromise = promisify(glob);
export default async () => {
try {
const rest = new REST({ version: '9'}).setToken(client.token);
const commandJSON = [];
client.commands.forEach(async (interaction) => {
commandJSON.push(interaction.command.toJSON());
});
console.log(`Attempting to sync '${commandJSON.length}' commands across '${client.guilds.cache.size}' discord servers.`);
// Sync commands, across, all discord servers.
await client.guilds.cache.forEach(async (guild, index) => {
await rest.put(Routes.applicationGuildCommands(client.user.id, guild.id), { body: commandJSON })
.then(() => console.log(`Commands synced with '${guild.name}'`))
.catch(e => console.log(e));
});
} catch (e) {
console.log('Failed to sync commands', e);
}
};