discordjs / Commando

Official command framework for discord.js
Apache License 2.0
497 stars 243 forks source link

Emit `disabledCommandRun` when running a disabled command #378

Open cocoliliace opened 3 years ago

cocoliliace commented 3 years ago

Resolved #336

cocoliliace commented 3 years ago

I noticed that disabled commands are checked in dispatcher.js while the rest of commandBlock events (nsfw, guildOnly, permission... etc.) are checked in message.run(). Should I move disabled commands to message.run() to make it consistent? Instead of emitting disabledCommandRun maybe we should emit commandBlock with an argument of disabled

Gawdl3y commented 3 years ago

The idea behind a command being disabled is to prevent any additional processing for it, so nothing in the command's code is run at all. Off the top of my head, moving the handling for this to CommandMessage#run would mean that it occurs after parsing arguments and such.

cocoliliace commented 3 years ago

It looks like the conditions are checked at the beginning of CommandMessage#run, right before parsing the arguments, so I think CommandMessage#run would still be able to return early upon detecting the disabled command. Currently, the check for whether a command is disabled happens on an if statement in CommandDispatcher#handleMessage, and CommandMessage#run is called in the corresponding else if branch. If we remove the if statement there, CommandMessage#run would be called and the disabled commands would be immediately handled at the top of CommandMessage#run, which is also where gulidOnly, nsfw, and permissions are checked.