-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy-commands.ts
More file actions
31 lines (27 loc) · 1.04 KB
/
deploy-commands.ts
File metadata and controls
31 lines (27 loc) · 1.04 KB
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
26
27
28
29
30
31
import { REST, type RESTPutAPIApplicationCommandsResult, Routes } from "discord.js";
import { commands } from "../commands/index.js";
import { config } from "../env.js";
export async function deployCommands(): Promise<void> {
const commandData = [...commands.values()].map((command) => command.data);
const rest = new REST({ version: "10" }).setToken(config.discord.token);
(await rest.put(Routes.applicationCommands(config.discord.clientId), {
body: [],
})) as RESTPutAPIApplicationCommandsResult;
try {
const result = (await rest.put(
Routes.applicationGuildCommands(config.discord.clientId, config.discord.serverId),
{
body: commandData,
}
)) as RESTPutAPIApplicationCommandsResult;
console.log(
`✅ Successfully deployed ${result.length} commands to guild ${config.discord.serverId}`
);
} catch (error) {
console.error("❌ Error deploying commands:", error);
}
}
// If run directly with `node deploy.ts`
if (import.meta.url === `file://${process.argv[1]}`) {
deployCommands();
}