How to properly handle UserErrors?

I'm using the official sapphire template and want to throw a UserError inside a context menu command. How do I correctly handle the error and send a message to the user? I saw contextMenuCommandDenied.ts and thought that would handle it but I don't get a response and the error is shown in the logs.
2 Replies
Favna
Favna2y ago
contextMenuCommandDenied is for precondition denials for context menu commands. Errors go in the error events. The full list of which can be found here: https://www.sapphirejs.dev/docs/Documentation/api-framework/#events. That said, that doesn't mean they aren't UserErrors. UserError is just a class that extends Error, it doesn't say anything of where it is thrown. You can check other bots to see how they handle errors.
Spinel
Spinel2y ago
Discord bots that use @sapphire/framework v4 - Official Bot Examples ᴱ ᴰ ᴶˢ - Archangel ᴱ ᴰ - Dragonite ᴱ ᴰ - Radon ᴱ ᴬ Discord bots that use @sapphire/framework v3 - Arima ᴱ - Nino ᴱ ᴰ - Operator ᴱ ᴬ ᴰ - Sapphire Application Commands Examples ᴱ - Spectera ᴬ Discord bots that use @sapphire/framework v2 - Materia ᴱ - RTByte ᴱ ᴬ - Skyra ᴬ ᴰ - YliasDiscordBot ᴬ : Uses ESM (if not specified then uses CJS) : Advanced bot (if not specified it is a simple bot, or not graded) : Uses Docker in production ᴶˢ: Written in JavaScript. If not specified then the bot is written in TypeScript.
Want results from more Discord servers?
Add your server