fix: user error now results in user friendly message

This commit is contained in:
TrèsAbhi committed 2023-11-01 11:21:30 -05:00
1 parent dfba8bd15f
commit d991be4934
1 file changed
+7 -8
@@ -20,7 +20,6 @@ export default async function handleChatInputCommand(
await interaction.deferReply(); await interaction.deferReply();
try {
if (registry.inPreview && interaction.guildId !== discord.tres_guild_id) { if (registry.inPreview && interaction.guildId !== discord.tres_guild_id) {
interaction.editReply({ interaction.editReply({
embeds: [ embeds: [
@@ -34,6 +33,7 @@ export default async function handleChatInputCommand(
return; return;
} }
try {
const returnable = await registry.handler(interaction); const returnable = await registry.handler(interaction);
if (registry.handlesInteraction) return; if (registry.handlesInteraction) return;
@@ -56,21 +56,20 @@ export default async function handleChatInputCommand(
), ),
]; ];
if (!(error instanceof UserError)) { if (error instanceof UserError) {
console.error(interaction.commandName, error);
interaction.editReply({ interaction.editReply({
embeds: [ embeds: [
embedNegative( embedNegative(
(error as Error).message, error.message,
`${ (error.cause as string | undefined) ??
(error as Error).cause ?? 'No further information is available.' 'No further information is available.',
}`,
), ),
], ],
components, components,
}); });
} else { } else {
console.error(interaction.commandName, error);
interaction.editReply({ interaction.editReply({
embeds: [ embeds: [
embedNegative( embedNegative(