Skip to content

Commit a159aa2

Browse files
committed
feat: enhance command deployment logic to support both global and guild-specific commands based on server ID
1 parent 8d60678 commit a159aa2

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/util/deploy.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
import { API } from '@discordjs/core/http-only';
2-
import { REST, type RESTPutAPIApplicationCommandsResult } from 'discord.js';
2+
import {
3+
REST,
4+
type RESTPutAPIApplicationCommandsResult,
5+
type RESTPutAPIApplicationGuildCommandsJSONBody,
6+
} from 'discord.js';
37
import { commands } from '../commands/index.js';
48
import { config } from '../env.js';
59

610
export async function deployCommands(): Promise<RESTPutAPIApplicationCommandsResult> {
711
const commandData = [...commands.values()].map((command) => command.data);
812

13+
const guildId = config.discord.serverId;
14+
915
const rest = new REST({ version: '10' }).setToken(config.discord.token);
1016
const api = new API(rest);
1117

12-
const result = await api.applicationCommands.bulkOverwriteGlobalCommands(
13-
config.discord.clientId,
14-
commandData
15-
);
18+
let result: RESTPutAPIApplicationCommandsResult;
19+
20+
if (guildId) {
21+
result = await api.applicationCommands.bulkOverwriteGuildCommands(
22+
config.discord.clientId,
23+
guildId,
24+
commandData as RESTPutAPIApplicationGuildCommandsJSONBody
25+
);
26+
} else {
27+
result = await api.applicationCommands.bulkOverwriteGlobalCommands(
28+
config.discord.clientId,
29+
commandData
30+
);
31+
}
1632

1733
console.log(`Successfully registered ${result.length} commands.`);
1834
return result;

0 commit comments

Comments
 (0)