From d991be4934b069eb51b68d13da5f7f99fb10f044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Wed, 1 Nov 2023 11:21:30 -0500 Subject: [PATCH] fix: user error now results in user friendly message --- .../handlers/chatInputCommand.ts | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/events/interactionCreate/handlers/chatInputCommand.ts b/src/events/interactionCreate/handlers/chatInputCommand.ts index 12fabf78f..fbad9dc6b 100644 --- a/src/events/interactionCreate/handlers/chatInputCommand.ts +++ b/src/events/interactionCreate/handlers/chatInputCommand.ts @@ -20,20 +20,20 @@ export default async function handleChatInputCommand( await interaction.deferReply(); + if (registry.inPreview && interaction.guildId !== discord.tres_guild_id) { + interaction.editReply({ + embeds: [ + embedWarning( + `\`/${registry.command.name}\` is in Public Preview`, + '[Join the official Discord server](https://discord.gg/nDt7AjGJQH) to gain early access to this command before it is released to the public.', + ), + ], + }); + + return; + } + try { - if (registry.inPreview && interaction.guildId !== discord.tres_guild_id) { - interaction.editReply({ - embeds: [ - embedWarning( - `\`/${registry.command.name}\` is in Public Preview`, - '[Join the official Discord server](https://discord.gg/nDt7AjGJQH) to gain early access to this command before it is released to the public.', - ), - ], - }); - - return; - } - const returnable = await registry.handler(interaction); if (registry.handlesInteraction) return; @@ -56,21 +56,20 @@ export default async function handleChatInputCommand( ), ]; - if (!(error instanceof UserError)) { - console.error(interaction.commandName, error); - + if (error instanceof UserError) { interaction.editReply({ embeds: [ embedNegative( - (error as Error).message, - `${ - (error as Error).cause ?? 'No further information is available.' - }`, + error.message, + (error.cause as string | undefined) ?? + 'No further information is available.', ), ], components, }); } else { + console.error(interaction.commandName, error); + interaction.editReply({ embeds: [ embedNegative(