Skip to content

Commit 88a9f4e

Browse files
authored
feat: remove command deploy from the main file (#14)
* 🌟 feat: remove command registration on bot startup * 🌟 feat: remove clearing of global commands in deploy script
1 parent a15b30a commit 88a9f4e

File tree

3 files changed

+1
-50
lines changed

3 files changed

+1
-50
lines changed

β€Žsrc/index.tsβ€Ž

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Client, GatewayIntentBits } from "discord.js";
22
import { config } from "./env.js";
3-
import { loadCommands, registerCommands } from "./utils/commands.js";
43
import { loadEvents } from "./utils/events.js";
54

65
const client = new Client({
@@ -12,9 +11,7 @@ const client = new Client({
1211
GatewayIntentBits.GuildMembers,
1312
});
1413

15-
loadCommands(client);
1614
loadEvents(client);
17-
registerCommands();
1815

1916
// Graceful shutdown
2017
process.on("SIGINT", async () => {

β€Žsrc/utils/commands.tsβ€Ž

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,8 @@
1-
import {
2-
type ChatInputCommandInteraction,
3-
type Client,
4-
Collection,
5-
REST,
6-
Routes,
7-
} from "discord.js";
8-
import { commands } from "../commands/index.js";
9-
import type { Command } from "../commands/types.js";
10-
import { config } from "../env.js";
1+
import type { ChatInputCommandInteraction } from "discord.js";
112

123
export const buildCommandString = (interaction: ChatInputCommandInteraction): string => {
134
const commandName = interaction.commandName;
145
return `/${commandName} ${interaction.options.data
156
.map((option) => `${option.name}:${option.value}`)
167
.join(" ")}`;
178
};
18-
19-
export async function loadCommands(client: Client) {
20-
if (!client.commands) {
21-
client.commands = new Collection<string, Command>();
22-
}
23-
24-
let loaded = 0;
25-
for (const command of commands.values()) {
26-
client.commands.set(command.data.name, command);
27-
loaded += 1;
28-
}
29-
30-
console.log(`Successfully loaded ${loaded} command handlers into client.commands.`);
31-
}
32-
33-
export async function registerCommands() {
34-
const commandsData = Array.from(commands.values()).map((command) => command.data);
35-
36-
try {
37-
const guildId = config.discord.serverId;
38-
const scope = guildId ? `guild ${guildId}` : "global";
39-
console.log(`Started refreshing ${commandsData.length} ${scope} application commands.`);
40-
41-
const rest = new REST({ version: "10" }).setToken(config.discord.token);
42-
43-
await rest.put(Routes.applicationGuildCommands(config.discord.clientId, guildId), {
44-
body: commandsData,
45-
});
46-
47-
console.log(`Successfully reloaded ${commandsData.length} ${scope} commands.`);
48-
} catch (error) {
49-
console.error(JSON.stringify(error, null, 2));
50-
}
51-
}

β€Žsrc/utils/deploy-commands.tsβ€Ž

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ export async function deployCommands(): Promise<void> {
77

88
const rest = new REST({ version: "10" }).setToken(config.discord.token);
99

10-
(await rest.put(Routes.applicationCommands(config.discord.clientId), {
11-
body: [],
12-
})) as RESTPutAPIApplicationCommandsResult;
1310
try {
1411
const result = (await rest.put(
1512
Routes.applicationGuildCommands(config.discord.clientId, config.discord.serverId),

0 commit comments

Comments
Β (0)