Preconditions
Using preconditions, If a user does not meet the requirements to run a command I want the bot delete the message instead of sending a message, how can I do it?
5 Replies
bump
you've already explained how you'd do it so I don't really get what you're stuck on? 😅 you'd just iterate over the command's preconditions to check if any of them fail and if so, delete the message based on that
You can use the
messageCommandDenied
event. I modified the code from https://www.sapphirejs.dev/docs/Guide/preconditions/reporting-precondition-failure to fit this use case. It would be something like:
I added the .catch(() => null)
to silently fail if the bot can't delete the message (it was deleted already, the bot doesn't have permissions, etc.)Sapphire Framework
Reporting precondition failure | Sapphire
When a precondition fails, it's usually important for the user to know why. For example, if they hit a cooldown or lack
The above would function for all preconditions. If you only want it for a single precondition, then delete the message the same way in the
messageRun
method. Suppose you only want it for certain preconditions. In that case, you can add shouldDeleteMessage
(or similar) to the context, and read that in the messageCommandDenied
event to see if you should delete the message. See the guide page I linked for examples of using precondition context.Let me look into it. Thanks!