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
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#L27Gotcha, so I could do some similar kind of listener for
chatInputCommandError
, and then just make my commands throw
an error?You can
throw
an error, yes.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)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 🩵🩷🤍🩷🩵
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?Oh right, I missed the subcommand part, sorry 😅
Correct
Dang I was also looking for this