From 0517a48549951307b8e55684ea169a81eeae71e4 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 23 Feb 2024 18:18:40 +0000 Subject: [PATCH] Add try/catch to command execution --- src/client/interactionCreate/Button.ts | 8 +++++++- src/client/interactionCreate/ChatInputCommand.ts | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/client/interactionCreate/Button.ts b/src/client/interactionCreate/Button.ts index fac2b78..6d6a926 100644 --- a/src/client/interactionCreate/Button.ts +++ b/src/client/interactionCreate/Button.ts @@ -12,6 +12,12 @@ export default class Button { return; } - item.Event.execute(interaction); + try { + item.Event.execute(interaction); + } catch (e) { + console.error(e); + + await interaction.reply("An error occurred while executing the event"); + } } } \ No newline at end of file diff --git a/src/client/interactionCreate/ChatInputCommand.ts b/src/client/interactionCreate/ChatInputCommand.ts index 3890744..784ce6e 100644 --- a/src/client/interactionCreate/ChatInputCommand.ts +++ b/src/client/interactionCreate/ChatInputCommand.ts @@ -22,6 +22,12 @@ export default class ChatInputCommand { itemToUse = itemForServer; } - itemToUse.Command.execute(interaction); + try { + itemToUse.Command.execute(interaction); + } catch (e) { + console.error(e); + + await interaction.reply("An error occurred while executing the command"); + } } } \ No newline at end of file -- 2.43.4