feat(commands): improve error feedback for use command

This commit is contained in:
syntaxbullet
2025-12-22 12:56:37 +01:00
parent 6e1e6abf2d
commit 75e586cee8

View File

@@ -7,6 +7,7 @@ import { inventory, items } from "@/db/schema";
import { eq, and, like } from "drizzle-orm"; import { eq, and, like } from "drizzle-orm";
import { DrizzleClient } from "@/lib/DrizzleClient"; import { DrizzleClient } from "@/lib/DrizzleClient";
import type { ItemUsageData } from "@/lib/types"; import type { ItemUsageData } from "@/lib/types";
import { UserError } from "@/lib/errors";
export const use = createCommand({ export const use = createCommand({
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@@ -53,7 +54,12 @@ export const use = createCommand({
await interaction.editReply({ embeds: [embed] }); await interaction.editReply({ embeds: [embed] });
} catch (error: any) { } catch (error: any) {
if (error instanceof UserError) {
await interaction.editReply({ embeds: [createErrorEmbed(error.message)] }); await interaction.editReply({ embeds: [createErrorEmbed(error.message)] });
} else {
console.error("Error using item:", error);
await interaction.editReply({ embeds: [createErrorEmbed("An unexpected error occurred while using the item.")] });
}
} }
}, },
autocomplete: async (interaction) => { autocomplete: async (interaction) => {