discord slash commands base
This commit is contained in:
34
src/discord.ts
Normal file
34
src/discord.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { REST } from '@discordjs/rest';
|
||||
import { Routes } from 'discord-api-types/v9';
|
||||
|
||||
const commands = [{
|
||||
name: 'queue',
|
||||
description: 'creates a queue'
|
||||
}];
|
||||
|
||||
/**
|
||||
* register/reload commands on guild(s)
|
||||
* @param token discord bot token
|
||||
* @param clientId discord bot client id
|
||||
* @param guildIds discord guild id(s)
|
||||
*/
|
||||
export async function registerCommands(token: string, clientId: string, guildIds: string|string[]) {
|
||||
|
||||
const rest = new REST({ version: '9' }).setToken(token);
|
||||
|
||||
if (typeof guildIds === 'string')
|
||||
guildIds = [guildIds];
|
||||
|
||||
for (let i = 0; i < guildIds.length; i++) {
|
||||
try {
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, guildIds[i]),
|
||||
{ body: commands },
|
||||
);
|
||||
console.log(`[${guildIds[i]}] registered command`);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user