#Throwing errors in commands/subcommands
1 messages · Page 1 of 1 (latest)
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
chatInputCommandDeniedis emitted: https://github.com/sapphiredev/framework/blob/main/src/listeners/application-commands/chat-input/CorePreChatInputCommandRun.ts#L13-L25 - Where
chatInputCommandErroris emitted: https://github.com/sapphiredev/framework/blob/main/src/listeners/application-commands/chat-input/CoreChatInputCommandAccepted.ts#L27
Gotcha, 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 @misty cipher
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 😅