From 386ed4205f9fa329cd21640efac77063a5194899 Mon Sep 17 00:00:00 2001 From: Taken Date: Wed, 3 Jan 2024 16:05:57 +0100 Subject: [PATCH] Updated event handlers to send error message only if prod --- src/utils/eventHandlers/autocomplete.ts | 41 ++++++++++++++--------- src/utils/eventHandlers/button.ts | 41 ++++++++++++++--------- src/utils/eventHandlers/command.ts | 43 ++++++++++++++++--------- src/utils/eventHandlers/contextmenu.ts | 41 ++++++++++++++--------- src/utils/eventHandlers/modal.ts | 43 ++++++++++++++++--------- 5 files changed, 132 insertions(+), 77 deletions(-) diff --git a/src/utils/eventHandlers/autocomplete.ts b/src/utils/eventHandlers/autocomplete.ts index 37e7fb1..211fc38 100644 --- a/src/utils/eventHandlers/autocomplete.ts +++ b/src/utils/eventHandlers/autocomplete.ts @@ -51,22 +51,33 @@ export default function loadAutocompleteEvents(client: Client, ft: FileType) { try { await autocomplete.execute(interaction) } catch (error) { - const channel = client.channels.cache.get(errorLogChannel) as GuildTextBasedChannel - if (!channel) { - console.log("No error log channel found.") - } + if (process.env.NODE_ENV !== "dev") { + const channel = client.channels.cache.get( + errorLogChannel, + ) as GuildTextBasedChannel + if (!channel) { + console.log("No error log channel found.") + } - await channel.send({ - embeds: [{ - title: "Autocomplete error occured", - description: String(error), - color: embedColor, - footer: { - icon_url: interaction.guild!.iconURL({ forceStatic: false })!, - text: interaction.user.username + " | " + interaction.commandName - } - }], - }) + await channel.send({ + embeds: [ + { + title: "Autocomplete error occured", + description: String(error), + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL({ + forceStatic: false, + })!, + text: + interaction.user.username + + " | " + + interaction.commandName, + }, + }, + ], + }) + } console.error(error) } }) diff --git a/src/utils/eventHandlers/button.ts b/src/utils/eventHandlers/button.ts index 54fa0f4..8ca27c9 100644 --- a/src/utils/eventHandlers/button.ts +++ b/src/utils/eventHandlers/button.ts @@ -39,22 +39,33 @@ export default function loadButtonEvents(client: Client, ft: FileType) { try { await button.execute(interaction) } catch (error) { - const channel = client.channels.cache.get(errorLogChannel) as GuildTextBasedChannel - if (!channel) { - console.log("No error log channel found.") - } + if (process.env.NODE_ENV !== "dev") { + const channel = client.channels.cache.get( + errorLogChannel, + ) as GuildTextBasedChannel + if (!channel) { + console.log("No error log channel found.") + } - await channel.send({ - embeds: [{ - title: "Button error occured", - description: String(error), - color: embedColor, - footer: { - icon_url: interaction.guild!.iconURL({ forceStatic: false })!, - text: interaction.user.username + " | " + interaction.customId - } - }], - }) + await channel.send({ + embeds: [ + { + title: "Button error occured", + description: String(error), + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL({ + forceStatic: false, + })!, + text: + interaction.user.username + + " | " + + interaction.customId, + }, + }, + ], + }) + } console.error(error) await interaction.reply({ content: "There was an error while executing this event!", diff --git a/src/utils/eventHandlers/command.ts b/src/utils/eventHandlers/command.ts index 95be3e1..758cbd7 100644 --- a/src/utils/eventHandlers/command.ts +++ b/src/utils/eventHandlers/command.ts @@ -40,24 +40,35 @@ export default function loadSlashCommandsEvents(client: Client, ft: FileType) { try { await command.execute(interaction, client) } catch (error) { - const channel = client.channels.cache.get(errorLogChannel) as GuildTextBasedChannel - if (!channel) { - console.log("No error log channel found.") + if (process.env.NODE_ENV !== "dev") { + const channel = client.channels.cache.get( + errorLogChannel, + ) as GuildTextBasedChannel + if (!channel) { + console.log("No error log channel found.") + } + + await channel.send({ + embeds: [ + { + title: "Command error occured", + description: String(error), + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL({ + forceStatic: false, + })!, + text: + interaction.user.username + + " | " + + interaction.commandName, + }, + }, + ], + }) } - await channel.send({ - embeds: [{ - title: "Command error occured", - description: String(error), - color: embedColor, - footer: { - icon_url: interaction.guild!.iconURL({ forceStatic: false })!, - text: interaction.user.username + " | " + interaction.commandName - } - }], - }) - - console.error(error) + // console.error(error) await interaction.reply({ content: "There was an error while executing this command!", ephemeral: true, diff --git a/src/utils/eventHandlers/contextmenu.ts b/src/utils/eventHandlers/contextmenu.ts index bbbfd07..5c17690 100644 --- a/src/utils/eventHandlers/contextmenu.ts +++ b/src/utils/eventHandlers/contextmenu.ts @@ -47,22 +47,33 @@ export default function loadContextMenuEvents(client: Client, ft: FileType) { try { await command.execute(interaction) } catch (error) { - const channel = client.channels.cache.get(errorLogChannel) as GuildTextBasedChannel - if (!channel) { - console.log("No error log channel found.") - } + if (process.env.NODE_ENV !== "dev") { + const channel = client.channels.cache.get( + errorLogChannel, + ) as GuildTextBasedChannel + if (!channel) { + console.log("No error log channel found.") + } - await channel.send({ - embeds: [{ - title: "Contextmenu error occured", - description: String(error), - color: embedColor, - footer: { - icon_url: interaction.guild!.iconURL({ forceStatic: false })!, - text: interaction.user.username + " | " + interaction.commandName - } - }], - }) + await channel.send({ + embeds: [ + { + title: "Contextmenu error occured", + description: String(error), + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL({ + forceStatic: false, + })!, + text: + interaction.user.username + + " | " + + interaction.commandName, + }, + }, + ], + }) + } console.error(error) await interaction.reply({ content: "There was an error while executing this command!", diff --git a/src/utils/eventHandlers/modal.ts b/src/utils/eventHandlers/modal.ts index 29e1883..4eb5531 100644 --- a/src/utils/eventHandlers/modal.ts +++ b/src/utils/eventHandlers/modal.ts @@ -41,23 +41,34 @@ export default function loadModalEvents(client: Client, ft: FileType) { try { await modal.execute(interaction) } catch (error) { - console.error(error) - const channel = client.channels.cache.get(errorLogChannel) as GuildTextBasedChannel - if (!channel) { - console.log("No error log channel found.") - } + if (process.env.NODE_ENV !== "dev") { + const channel = client.channels.cache.get( + errorLogChannel, + ) as GuildTextBasedChannel + if (!channel) { + console.log("No error log channel found.") + } - await channel.send({ - embeds: [{ - title: "Button error occured", - description: String(error), - color: embedColor, - footer: { - icon_url: interaction.guild!.iconURL({ forceStatic: false })!, - text: interaction.user.username + " | " + interaction.customId - } - }], - }) + await channel.send({ + embeds: [ + { + title: "Button error occured", + description: String(error), + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL({ + forceStatic: false, + })!, + text: + interaction.user.username + + " | " + + interaction.customId, + }, + }, + ], + }) + } + console.error(error) await interaction.reply({ content: "There was an error while executing this modal!", ephemeral: true,