how to make message when command is in cooldown?
hey, so my default defaultCooldownDuration inside my Client is 4000ms(4 seconds), but when i run the command multiple times it won't respond because it's in cooldown, i just want to send a single message saying the bot is in cooldown, how an i do that?
Solution:Jump to solution
Implement messageCommandDenied / chatInputCommandDenied / contextMenuCommandDenied https://www.sapphirejs.dev/docs/Guide/preconditions/creating-your-own-preconditions
Sapphire Framework
Creating your own preconditions | Sapphire
Just as we did in Creating Commands, we will start by creating a preconditions subdirectory in
14 Replies
Solution
Implement messageCommandDenied / chatInputCommandDenied / contextMenuCommandDenied https://www.sapphirejs.dev/docs/Guide/preconditions/creating-your-own-preconditions
Sapphire Framework
Creating your own preconditions | Sapphire
Just as we did in Creating Commands, we will start by creating a preconditions subdirectory in
all are already implemented
events or preconditions?
then your preconditions are already handled. I'm not sure what you want to know then.
Those are listeners
yes
messageCommandDenied
i want to send a message in the channel when a command is in cooldown
That should already happen now. This message should be sent: https://github.com/sapphiredev/framework/blob/e9a7966f0bad532deb1a7da617b57db902ae06a6/src/preconditions/Cooldown.ts#L77-L78
i see, but the bot won't send that message
Does your listener trigger at all?
Like for other preconditions
my
messageCommandSuccess
works just fine
does not seem like messageCommandDenied
works
oh now it does seem to work but the timer goes back
is there also a way to just send that message once and that's it?The timer counts down because it uses a Discord formatted timer... there is practically no reason to send a static unchanging time because at least this way people can constantly tell how long remains without using the command over and over again to see it
But if you really don't want it then you identify the precondition through
error.identifier
(currently not destructured in your listener) then use payload.context.remaining
to get the amount of milliseconds the cooldown remains then send a custom message instead of the default one provided by Sapphirei see, thanks for that
now, is there also a way to just send that message once and that's it?
what do you mean
like if you keep executing the command it would send the ratelimiter message multiple times and that could cause the bot to be ratelimited by discord
like just send it once and then ignore the rest of the executions while ratelimited
By default no there is not because the precondition will always trigger which will always trigger the listener. You could write some mechanic in that uses identifier and message author to keep a cache of whose been informed already. Basic JavaScript stuff there.
Or you could switch to chat input commands then you can make it send as an ephemeral reply to the user instead so it won't spam the chat 🤷
oh i see