ttt-discord-bot/server/discordAdapter.ts

21 lines
732 B
TypeScript
Raw Normal View History

2021-11-08 17:34:26 +01:00
import { REST } from '@discordjs/rest'
import { commandList, discordCommand } from './constants'
import { Routes } from 'discord-api-types/v9'
import { config } from './configuration'
export default class DiscordAdapter {
private rest: REST
public constructor() {
this.rest = new REST({ version: '9' }).setToken(config.token)
}
public async registerCommands(pCommands: discordCommand[]) {
if (!config.debug)
try {
console.log('Refreshing slash commands')
await this.rest.put(Routes.applicationGuildCommands(config.client_id, config.guild_id), { body: pCommands })
console.log('Successfully refreshed slash commands')
} catch (error) {
console.log(`Error refreshing slash commands: ${error}`)
}
}
}