-
Notifications
You must be signed in to change notification settings - Fork 0
/
refreshCommands.ts
25 lines (23 loc) · 1.11 KB
/
refreshCommands.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { REST, RESTPutAPIApplicationCommandsResult, Routes } from "discord.js";
import { Command } from "./types/Command";
export default async function refreshCommands(commands:Command[], token: string, clientID: string) {
const commandJSON = commands.map(({data})=> {
data
});
const rest = new REST().setToken(token);
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationCommands(clientID),
{ body: [] },
) as RESTPutAPIApplicationCommandsResult;
console.log(`Unregistered ${data.length} existing commands.`);
await rest.post(Routes.applicationCommands(clientID),
{body: commandJSON});
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
}