aboutsummaryrefslogtreecommitdiff
path: root/core/SlashCommandsRefresher.ts
diff options
context:
space:
mode:
Diffstat (limited to 'core/SlashCommandsRefresher.ts')
-rw-r--r--core/SlashCommandsRefresher.ts35
1 files changed, 35 insertions, 0 deletions
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