Skip to content

Commit 0c89a32

Browse files
committed
Add command registration after command execution in interaction handling. Introduce tryRegisterCommands function to manage command registration with error handling, improving overall command execution flow.
1 parent 5d25c75 commit 0c89a32

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/events/interactionCreate.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ChatInputCommandInteraction, Events, Interaction } from 'discord.js';
22
import changeVcNotifyRole from '../commands/changeVcNotifyRole';
33
import setSessionStartMessage from '../commands/setSessionStartMessage';
4+
import { registerCommands } from '../utils/commandRegistration';
45

56
interface Command {
67
execute: (interaction: ChatInputCommandInteraction) => Promise<void>;
@@ -21,6 +22,7 @@ export default {
2122

2223
try {
2324
await command.execute(interaction);
25+
await tryRegisterCommands(interaction);
2426
} catch (error) {
2527
console.error(
2628
`Error executing command ${interaction.commandName}:`,
@@ -31,6 +33,25 @@ export default {
3133
},
3234
};
3335

36+
async function tryRegisterCommands(interaction: Interaction): Promise<void> {
37+
try {
38+
const clientId = interaction.client.user?.id;
39+
const token = process.env.DISCORD_BOT_TOKEN;
40+
if (clientId && token) {
41+
await registerCommands(clientId, token);
42+
} else {
43+
console.warn(
44+
'Client ID or bot token not set; skipping command registration.'
45+
);
46+
}
47+
} catch (error) {
48+
console.error(
49+
'Error re-registering commands after command execution:',
50+
error
51+
);
52+
}
53+
}
54+
3455
async function sendErrorResponse(
3556
interaction: ChatInputCommandInteraction
3657
): Promise<void> {

0 commit comments

Comments
 (0)