From 7b5df4ca0a5bd6fcf033ef40563599593b156910 Mon Sep 17 00:00:00 2001 From: Minteck Date: Wed, 13 Jul 2022 23:34:21 +0200 Subject: Initial commit --- core/SlashCommandsRefresher.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 core/SlashCommandsRefresher.ts (limited to 'core/SlashCommandsRefresher.ts') diff --git a/core/SlashCommandsRefresher.ts b/core/SlashCommandsRefresher.ts new file mode 100644 index 0000000..0503366 --- /dev/null +++ b/core/SlashCommandsRefresher.ts @@ -0,0 +1,35 @@ +import {LogManager} from "./LogManager"; +import {REST} from '@discordjs/rest'; +import {Routes} from 'discord-api-types/v9'; +import {CommandsLoader} from "./CommandsLoader"; + +export class SlashCommandsRefresher { + public static async refresh(clientId: string, token: string) { + const rest = new REST({version: '9'}).setToken(token); + try { + const commandsLoader = new CommandsLoader(); + LogManager.info('Started refreshing application (/) commands.'); + + await rest.put( + Routes.applicationCommands(clientId), + {body: []}, + ); + + try { + await rest.put( + Routes.applicationGuildCommands(clientId, "996331009744318534"), + {body: commandsLoader.slashCommands()}, + ); + } catch (e) { + await rest.put( + Routes.applicationGuildCommands(clientId, "969994404184084560"), + {body: commandsLoader.slashCommands()}, + ); + } + + LogManager.info('Successfully reloaded application (/) commands. Changes may take a while to appear on Discord.'); + } catch (error) { + console.error(error); + } + } +} \ No newline at end of file -- cgit