Skip to content

Commit 00c2bde

Browse files
authoredJan 5, 2025··
Fix crash on Reacord-based command usage (#107)
This was crashing because Reacord has its own handlers for commands, which meant that we wouldn’t be able to find a handler when one comes in. Instead of throwing an error, return early.
1 parent 2550438 commit 00c2bde

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed
 

Diff for: ‎app/discord/deployCommands.server.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const deployCommands = async (client: Client) => {
4343
switch (interaction.type) {
4444
case InteractionType.ApplicationCommand: {
4545
const config = matchCommand(interaction.commandName);
46+
if (!config) return;
4647

4748
if (
4849
isMessageContextCommand(config) &&
@@ -66,6 +67,8 @@ export const deployCommands = async (client: Client) => {
6667

6768
case InteractionType.MessageComponent: {
6869
const config = matchCommand(interaction.customId);
70+
if (!config) return;
71+
6972
if (
7073
isMessageComponentCommand(config) &&
7174
interaction.isMessageComponent()
@@ -76,6 +79,8 @@ export const deployCommands = async (client: Client) => {
7679
}
7780
case InteractionType.ModalSubmit: {
7881
const config = matchCommand(interaction.customId);
82+
if (!config) return;
83+
7984
if (isModalCommand(config) && interaction.isModalSubmit()) {
8085
config.handler(interaction);
8186
}
@@ -236,15 +241,10 @@ export const registerCommand = (config: AnyCommand | AnyCommand[]) => {
236241
commands.set(config.command.name, config);
237242
};
238243
const matchCommand = (customId: string) => {
239-
let config = commands.get(customId);
244+
const config = commands.get(customId);
240245
if (config) {
241246
return config;
242247
}
243248
const key = [...commands.keys()].find((k) => customId.startsWith(`${k}|`));
244-
config = commands.get(key || "??");
245-
if (config) {
246-
return config;
247-
}
248-
console.error([...commands.keys()].join(" "));
249-
throw new Error(`No command found for ${customId}`);
249+
return commands.get(key || "??");
250250
};

0 commit comments

Comments
 (0)
Please sign in to comment.