discord slash commands base

This commit is contained in:
2022-01-27 16:51:48 -06:00
parent 945b0967f9
commit 0fbd8f9c62
2 changed files with 75 additions and 0 deletions

34
src/discord.ts Normal file
View 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);
}
}
}