Throwing errors in commands/subcommands

Just curious if there is a way to throw an error in an application command/subcommand and have it handled by the chatInputCommandDenied listener, similar to how preconditions work. Some kind of this.error that can be sent and handled by the listener. Does this exist or can I write something to do that?
9 Replies
kyra
kyra9mo ago
chatInputCommandDenied is exclusively for preconditions that return this.error(). However, you have the chatInputCommandError event to handle errors thrown by commands. From source code: - Where chatInputCommandDenied is emitted: https://github.com/sapphiredev/framework/blob/main/src/listeners/application-commands/chat-input/CorePreChatInputCommandRun.ts#L13-L25 - Where chatInputCommandError is emitted: https://github.com/sapphiredev/framework/blob/main/src/listeners/application-commands/chat-input/CoreChatInputCommandAccepted.ts#L27
Tony
Tony9mo ago
Gotcha, so I could do some similar kind of listener for chatInputCommandError, and then just make my commands throw an error?
kyra
kyra9mo ago
You can throw an error, yes.
Tony
Tony9mo ago
Alright, I'll have a mess about and see if I can get something to work, thanks I've quickly just thrown a throw 'Test' into a command and seems that the chatInputCommandSuccess is being emitted, not chatInputCommandError (as the debug logger is going off, not any code I wrote for the error)
Favna
Favna9mo ago
For subcommands it's a separate listener chatInputSubcommandError if i remember correctly but there is an SubcommandsEvents constant exported from the plugin so easier to just use that Likewise for subcommand preconditions are their own event CC @kyra 🩵🩷🤍🩷🩵
Tony
Tony9mo ago
Ahh, gotcha Yep, now that's working perfectly, awesome Also assumg that means I'll need to also have a chatInputSubommandDenied listener for subcommand preconditions?
kyra
kyra9mo ago
Oh right, I missed the subcommand part, sorry 😅
Favna
Favna9mo ago
Correct
MRDGH2821
MRDGH28219mo ago
Dang I was also looking for this
Want results from more Discord servers?
Add your server