Updated event handlers to send error message only if prod

This commit is contained in:
2024-01-03 16:05:57 +01:00
parent 7e00569fbe
commit 386ed4205f
5 changed files with 132 additions and 77 deletions

View File

@@ -51,22 +51,33 @@ export default function loadAutocompleteEvents(client: Client, ft: FileType) {
try { try {
await autocomplete.execute(interaction) await autocomplete.execute(interaction)
} catch (error) { } catch (error) {
const channel = client.channels.cache.get(errorLogChannel) as GuildTextBasedChannel if (process.env.NODE_ENV !== "dev") {
const channel = client.channels.cache.get(
errorLogChannel,
) as GuildTextBasedChannel
if (!channel) { if (!channel) {
console.log("No error log channel found.") console.log("No error log channel found.")
} }
await channel.send({ await channel.send({
embeds: [{ embeds: [
{
title: "Autocomplete error occured", title: "Autocomplete error occured",
description: String(error), description: String(error),
color: embedColor, color: embedColor,
footer: { footer: {
icon_url: interaction.guild!.iconURL({ forceStatic: false })!, icon_url: interaction.guild!.iconURL({
text: interaction.user.username + " | " + interaction.commandName forceStatic: false,
} })!,
}], text:
interaction.user.username +
" | " +
interaction.commandName,
},
},
],
}) })
}
console.error(error) console.error(error)
} }
}) })

View File

@@ -39,22 +39,33 @@ export default function loadButtonEvents(client: Client, ft: FileType) {
try { try {
await button.execute(interaction) await button.execute(interaction)
} catch (error) { } catch (error) {
const channel = client.channels.cache.get(errorLogChannel) as GuildTextBasedChannel if (process.env.NODE_ENV !== "dev") {
const channel = client.channels.cache.get(
errorLogChannel,
) as GuildTextBasedChannel
if (!channel) { if (!channel) {
console.log("No error log channel found.") console.log("No error log channel found.")
} }
await channel.send({ await channel.send({
embeds: [{ embeds: [
{
title: "Button error occured", title: "Button error occured",
description: String(error), description: String(error),
color: embedColor, color: embedColor,
footer: { footer: {
icon_url: interaction.guild!.iconURL({ forceStatic: false })!, icon_url: interaction.guild!.iconURL({
text: interaction.user.username + " | " + interaction.customId forceStatic: false,
} })!,
}], text:
interaction.user.username +
" | " +
interaction.customId,
},
},
],
}) })
}
console.error(error) console.error(error)
await interaction.reply({ await interaction.reply({
content: "There was an error while executing this event!", content: "There was an error while executing this event!",

View File

@@ -40,24 +40,35 @@ export default function loadSlashCommandsEvents(client: Client, ft: FileType) {
try { try {
await command.execute(interaction, client) await command.execute(interaction, client)
} catch (error) { } catch (error) {
const channel = client.channels.cache.get(errorLogChannel) as GuildTextBasedChannel if (process.env.NODE_ENV !== "dev") {
const channel = client.channels.cache.get(
errorLogChannel,
) as GuildTextBasedChannel
if (!channel) { if (!channel) {
console.log("No error log channel found.") console.log("No error log channel found.")
} }
await channel.send({ await channel.send({
embeds: [{ embeds: [
{
title: "Command error occured", title: "Command error occured",
description: String(error), description: String(error),
color: embedColor, color: embedColor,
footer: { footer: {
icon_url: interaction.guild!.iconURL({ forceStatic: false })!, icon_url: interaction.guild!.iconURL({
text: interaction.user.username + " | " + interaction.commandName forceStatic: false,
} })!,
}], text:
interaction.user.username +
" | " +
interaction.commandName,
},
},
],
}) })
}
console.error(error) // console.error(error)
await interaction.reply({ await interaction.reply({
content: "There was an error while executing this command!", content: "There was an error while executing this command!",
ephemeral: true, ephemeral: true,

View File

@@ -47,22 +47,33 @@ export default function loadContextMenuEvents(client: Client, ft: FileType) {
try { try {
await command.execute(interaction) await command.execute(interaction)
} catch (error) { } catch (error) {
const channel = client.channels.cache.get(errorLogChannel) as GuildTextBasedChannel if (process.env.NODE_ENV !== "dev") {
const channel = client.channels.cache.get(
errorLogChannel,
) as GuildTextBasedChannel
if (!channel) { if (!channel) {
console.log("No error log channel found.") console.log("No error log channel found.")
} }
await channel.send({ await channel.send({
embeds: [{ embeds: [
{
title: "Contextmenu error occured", title: "Contextmenu error occured",
description: String(error), description: String(error),
color: embedColor, color: embedColor,
footer: { footer: {
icon_url: interaction.guild!.iconURL({ forceStatic: false })!, icon_url: interaction.guild!.iconURL({
text: interaction.user.username + " | " + interaction.commandName forceStatic: false,
} })!,
}], text:
interaction.user.username +
" | " +
interaction.commandName,
},
},
],
}) })
}
console.error(error) console.error(error)
await interaction.reply({ await interaction.reply({
content: "There was an error while executing this command!", content: "There was an error while executing this command!",

View File

@@ -41,23 +41,34 @@ export default function loadModalEvents(client: Client, ft: FileType) {
try { try {
await modal.execute(interaction) await modal.execute(interaction)
} catch (error) { } catch (error) {
console.error(error) if (process.env.NODE_ENV !== "dev") {
const channel = client.channels.cache.get(errorLogChannel) as GuildTextBasedChannel const channel = client.channels.cache.get(
errorLogChannel,
) as GuildTextBasedChannel
if (!channel) { if (!channel) {
console.log("No error log channel found.") console.log("No error log channel found.")
} }
await channel.send({ await channel.send({
embeds: [{ embeds: [
{
title: "Button error occured", title: "Button error occured",
description: String(error), description: String(error),
color: embedColor, color: embedColor,
footer: { footer: {
icon_url: interaction.guild!.iconURL({ forceStatic: false })!, icon_url: interaction.guild!.iconURL({
text: interaction.user.username + " | " + interaction.customId forceStatic: false,
} })!,
}], text:
interaction.user.username +
" | " +
interaction.customId,
},
},
],
}) })
}
console.error(error)
await interaction.reply({ await interaction.reply({
content: "There was an error while executing this modal!", content: "There was an error while executing this modal!",
ephemeral: true, ephemeral: true,