-
Notifications
You must be signed in to change notification settings - Fork 0
/
slashCommands.ts
30 lines (24 loc) · 971 Bytes
/
slashCommands.ts
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
import * as fs from 'fs'
import {DiscordAuth} from './discordbot/discordAuth';
import {promisify} from 'util';
import {Routes} from 'discord.js';
export async function reloadSlashCommands(auth: DiscordAuth, guild: string): Promise<boolean> {
try {
console.log('Started refreshing application (/) commands.');
const asyncReaddir = promisify(fs.readdir)
const commandFiles = (await asyncReaddir('./commands')).filter(f => f.endsWith('.js'));
const commands = [];
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
}
await auth.client.rest.put(Routes.applicationGuildCommands(auth.clientId, guild), {
body: commands
});
console.log('Successfully reloaded application (/) commands.');
return true;
} catch (error) {
console.error(error);
return false;
}
}