Skip to content

Commit 8834c4e

Browse files
authored
Merge pull request #12 from ianeli1/try-fix-unknown-interaction
Aid/improve handling of `Unknown Interaction` discord.js errors
2 parents ade6847 + ff31a98 commit 8834c4e

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/action.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ export const ActionFactory = (
243243
>;
244244
if (invoker.replied || invoker.deferred) {
245245
//if message has been deferred, just update content
246-
return reply ? invoker.editReply(await reply) : undefined;
246+
return reply ? await invoker.editReply(await reply) : undefined;
247247
}
248248
reply && (await invoker.reply(await reply));
249-
return invoker.fetchReply();
249+
return await invoker.fetchReply();
250250
}
251251

252252
return reply

src/bot.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { errorTrigger, RoutedAction, typoTrigger } from "./routedAction";
1919
import { ApplicationCommands } from "./applicationCommands";
2020
import { InteractionHandler } from "./interactionHandler";
2121
import { IAction } from "./IAction";
22+
import { ActionError } from "./error";
2223

2324
interface BotOptions {
2425
prefix?: string;
@@ -383,7 +384,10 @@ export class Bot extends BotBase {
383384
try {
384385
await action.executeAll();
385386
} catch (e) {
386-
for (const errorAction of action.getError({ args: e.message })) {
387+
for (const errorAction of action.getError({
388+
args: e.message,
389+
error: e instanceof ActionError ? e.e : e,
390+
})) {
387391
if (!errorAction) break;
388392
try {
389393
await errorAction.executeAll();

src/interactionHandler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ export class InteractionHandler {
100100

101101
@autobind
102102
private async handleSlashCommandInteraction(interaction: CommandInteraction) {
103+
interaction
104+
.deferReply()
105+
.catch((e) =>
106+
this.report(
107+
`An error ocurred while deferring interaction ${interaction.id}: ${e?.message}`
108+
)
109+
);
103110
const action = this.bot.router.findAction(
104111
this.constructFullTrigger(interaction)
105112
);

0 commit comments

Comments
 (0)