Updated error handling

This commit is contained in:
2024-01-09 14:44:01 +01:00
parent 60c655c334
commit 4090446dee
4 changed files with 70 additions and 21 deletions

View File

@@ -41,12 +41,11 @@ export default function loadButtonEvents(client: Client, ft: FileType) {
await button.execute(interaction) await button.execute(interaction)
} catch (error) { } catch (error) {
if (process.env.NODE_ENV !== "dev") { if (process.env.NODE_ENV !== "dev") {
await logToChannel("error", { await logToChannel("error", {
embeds: [ embeds: [
{ {
title: "Button error occured", title: "Button error occured",
description: String(error), description: "```" + error + "```",
color: embedColor, color: embedColor,
footer: { footer: {
icon_url: interaction.guild!.iconURL() || undefined, icon_url: interaction.guild!.iconURL() || undefined,
@@ -59,11 +58,24 @@ export default function loadButtonEvents(client: Client, ft: FileType) {
], ],
}) })
} }
console.error(error) console.error(error)
await interaction.reply({ if (!interaction.deferred) {
content: "There was an error while executing this event!", await interaction.reply({
ephemeral: true, embeds: [{
}) description: "There was an error while executing this button!",
color: embedColor,
}],
ephemeral: true,
})
} else {
await interaction.editReply({
embeds: [{
description: "There was an error while executing this button! 2",
color: embedColor,
}]
})
}
} }
}) })
} }

View File

@@ -46,7 +46,7 @@ export default function loadSlashCommandsEvents(client: Client, ft: FileType) {
embeds: [ embeds: [
{ {
title: "Command error occured", title: "Command error occured",
description: String(error), description: "```" + error + "```",
color: embedColor, color: embedColor,
footer: { footer: {
icon_url: interaction.guild!.iconURL() || undefined, icon_url: interaction.guild!.iconURL() || undefined,
@@ -61,10 +61,22 @@ export default function loadSlashCommandsEvents(client: Client, ft: FileType) {
} }
console.error(error) console.error(error)
await interaction.reply({ if (!interaction.deferred) {
content: "There was an error while executing this command!", await interaction.reply({
ephemeral: true, embeds: [{
}) description: "There was an error while executing this command!",
color: embedColor,
}],
ephemeral: true,
})
} else {
await interaction.editReply({
embeds: [{
description: "There was an error while executing this command!",
color: embedColor,
}]
})
}
} }
}) })
} }

View File

@@ -53,7 +53,7 @@ export default function loadContextMenuEvents(client: Client, ft: FileType) {
embeds: [ embeds: [
{ {
title: "Contextmenu error occured", title: "Contextmenu error occured",
description: String(error), description: "```" + error + "```",
color: embedColor, color: embedColor,
footer: { footer: {
icon_url: interaction.guild!.iconURL() || undefined, icon_url: interaction.guild!.iconURL() || undefined,
@@ -66,11 +66,24 @@ export default function loadContextMenuEvents(client: Client, ft: FileType) {
], ],
}) })
} }
console.error(error) console.error(error)
await interaction.reply({ if (!interaction.deferred) {
content: "There was an error while executing this command!", await interaction.reply({
ephemeral: true, embeds: [{
}) description: "There was an error while executing this contextmenu command!",
color: embedColor,
}],
ephemeral: true,
})
} else {
await interaction.editReply({
embeds: [{
description: "There was an error while executing this contextmenu command!",
color: embedColor,
}]
})
}
} }
}) })
} }

View File

@@ -47,7 +47,7 @@ export default function loadModalEvents(client: Client, ft: FileType) {
embeds: [ embeds: [
{ {
title: "Button error occured", title: "Button error occured",
description: String(error), description: "```" + error + "```",
color: embedColor, color: embedColor,
footer: { footer: {
icon_url: interaction.guild!.iconURL() || undefined, icon_url: interaction.guild!.iconURL() || undefined,
@@ -60,11 +60,23 @@ export default function loadModalEvents(client: Client, ft: FileType) {
], ],
}) })
} }
console.error(error) console.error(error)
await interaction.reply({ if (!interaction.deferred) {
content: "There was an error while executing this modal!", await interaction.reply({
ephemeral: true, embeds: [{
}) description: "There was an error while executing this modal!",
color: embedColor
}]
})
} else {
await interaction.editReply({
embeds: [{
description: "There was an error while executing this modal!",
color: embedColor
}]
})
}
} }
}) })
} }