Slash Command Cooldowns
Cooldowns prevent users from spamming the same slash command repeatedly. When a cooldown is active, Discord shows an error message telling the user they’re on cooldown.
How Cooldowns Work
Section titled “How Cooldowns Work”When a user tries to execute a slash command while on cooldown:
- Discord triggers the
on slash cooldownevent instead of the normal command event - Your bot can respond with a custom message
- Or you can cancel the cooldown to allow execution anyway
Setting Up Cooldowns
Section titled “Setting Up Cooldowns”Cooldowns are defined directly on the slash command:
on ready: set {_cmd} to new slash command named "vote" with description "Vote for something"
# Set a 1-hour cooldown (applies per user) set cooldown of {_cmd} to 1 hour
update {_cmd} globally in event-botHandling Cooldown Events
Section titled “Handling Cooldown Events”Use the on slash cooldown event to handle users on cooldown:
on slash cooldown: # Get how long until the cooldown expires set {_remaining} to remaining time of cooldown
# Reply with a friendly message reply with hidden "You're on cooldown! Try again in %{_remaining}%"Cooldown Event Values
Section titled “Cooldown Event Values”event-string— Command nameevent-user— User on cooldownevent-guild— Guild where command is usedremaining time of cooldown— Time until cooldown expires
Bypassing Cooldowns
Section titled “Bypassing Cooldowns”You can allow users to bypass cooldowns by cancelling the event:
on slash cooldown: # Allow admins to bypass cooldown if event-user has permission "ADMINISTRATOR": cancel event stop
# Reject others reply with hidden "You're on cooldown!"Common Patterns
Section titled “Common Patterns”Per-User Cooldown
Section titled “Per-User Cooldown”Default behavior — each user has their own cooldown:
set cooldown of {_cmd} to 30 secondsGlobal Cooldown (All Users)
Section titled “Global Cooldown (All Users)”Prevent any user from using the command for a period:
set global cooldown of {_cmd} to 5 minutesTiered Cooldowns
Section titled “Tiered Cooldowns”Different cooldowns for different user types:
on slash cooldown: if event-user has permission "ADMINISTRATOR": cancel event else if event-user has role "Premium": # Premium users get shorter cooldown reply with hidden "Premium cooldown: %remaining time of cooldown%" else: reply with hidden "Regular cooldown: %remaining time of cooldown%"Best Practices
Section titled “Best Practices”- Use reasonable cooldowns — 5-60 seconds is typical, avoid excessive spam prevention
- Provide feedback — Always tell users when they’re on cooldown and when it expires
- Consider permissions — Admins or moderators might bypass cooldowns
- Test thoroughly — Ensure cooldown timing matches your needs
Example: Vote Command
Section titled “Example: Vote Command”on ready: set {_vote} to new slash command named "vote" with description "Vote for the server" set cooldown of {_vote} to 1 hour update {_vote} globally in event-bot
on slash command: if event-string is "vote": # User voted, increment counter add 1 to {votes} reply with "✅ Thanks for voting! Total votes: %{votes}%"
on slash cooldown: if event-string is "vote": set {_time} to remaining time of cooldown reply with hidden "You already voted! Come back in %{_time}%"Troubleshooting
Section titled “Troubleshooting”Cooldown Not Working
Section titled “Cooldown Not Working”- Verify cooldown is set on the command
- Check that Discord received the command update (can take up to 1 hour for global commands)
- Use guild commands for instant testing
Event Not Firing
Section titled “Event Not Firing”- Ensure you have an
on slash cooldownhandler - Verify the command name matches exactly
Next Steps
Section titled “Next Steps”- Explore Slash Commands for more command features
- Learn about Interactions Overview