Skip to content

Add configurable per-user command cooldown - #75

Open
Saksham-official wants to merge 2 commits into
TheCodeVerseHub:mainfrom
Saksham-official:add-command-cooldown
Open

Saksham-official wants to merge 2 commits into
TheCodeVerseHub:mainfrom
Saksham-official:add-command-cooldown

Conversation

@Saksham-official

@Saksham-official Saksham-official commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

This PR adds a default per-user cooldown system to prevent command spamming, addressing #29.

What was done:

  • Added CooldownManager in utils/cooldown.py to track timestamps per user, calculate retry intervals, and prune old entries if the cache grows large.
  • Added COMMAND_COOLDOWN_SECONDS to Config (defaults to 3.0s, documented in .env.example). Setting it to 0 or negative disables the cooldown.
  • Added global checks for prefix commands (@self.check) and slash commands (tree.interaction_check, scoped to application commands so autocomplete and buttons aren't affected).
  • Commands that define their own custom cooldowns (like ?fridge in fun.py or tts.py) keep their existing rate limits and are skipped by the default gate.
  • Bot owner (OWNER_ID) bypasses the cooldown.
  • Connected self.tree.on_error = self.on_app_command_error so slash cooldown errors properly trigger the existing ephemeral response handler.
  • Added unit tests in tests/test_cooldown.py.

Verified locally with pytest, ruff check ., and mypy ..

Closes #29

@Saksham-official
Saksham-official requested review from a team as code owners September 15, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add command cooldown system

1 participant