diff options
| author | Rapptz <[email protected]> | 2021-07-02 05:39:54 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-07-02 05:39:54 -0400 |
| commit | a3d7e06f2585ba8257b67c25dcd809ce1bd11c71 (patch) | |
| tree | 741feed34c40368411dadb5401a2cf0623bad6ba | |
| parent | [commands] Mention that dynamic_cooldown callable can return None (diff) | |
| download | discord.py-a3d7e06f2585ba8257b67c25dcd809ce1bd11c71.tar.xz discord.py-a3d7e06f2585ba8257b67c25dcd809ce1bd11c71.zip | |
[commands] Add back CommandOnCooldown.type
| -rw-r--r-- | discord/ext/commands/cooldowns.py | 4 | ||||
| -rw-r--r-- | discord/ext/commands/core.py | 2 | ||||
| -rw-r--r-- | discord/ext/commands/errors.py | 9 |
3 files changed, 11 insertions, 4 deletions
diff --git a/discord/ext/commands/cooldowns.py b/discord/ext/commands/cooldowns.py index d7fe404f..fe9930e1 100644 --- a/discord/ext/commands/cooldowns.py +++ b/discord/ext/commands/cooldowns.py @@ -148,6 +148,10 @@ class CooldownMapping: def valid(self): return self._cooldown is not None + @property + def type(self): + return self._type + @classmethod def from_cooldown(cls, rate, per, type): return cls(Cooldown(rate, per), type) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 509df057..586fb470 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -731,7 +731,7 @@ class Command(_BaseCommand): if bucket is not None: retry_after = bucket.update_rate_limit(current) if retry_after: - raise CommandOnCooldown(bucket, retry_after) + raise CommandOnCooldown(bucket, retry_after, self._buckets.type) async def prepare(self, ctx): ctx.command = self diff --git a/discord/ext/commands/errors.py b/discord/ext/commands/errors.py index 227985f4..901a0e56 100644 --- a/discord/ext/commands/errors.py +++ b/discord/ext/commands/errors.py @@ -460,14 +460,17 @@ class CommandOnCooldown(CommandError): Attributes ----------- cooldown: ``Cooldown`` - A class with attributes ``rate``, ``per``, and ``type`` similar to - the :func:`.cooldown` decorator. + A class with attributes ``rate`` and ``per`` similar to the + :func:`.cooldown` decorator. + type: :class:`BucketType` + The type associated with the cooldown. retry_after: :class:`float` The amount of seconds to wait before you can retry again. """ - def __init__(self, cooldown, retry_after): + def __init__(self, cooldown, retry_after, type): self.cooldown = cooldown self.retry_after = retry_after + self.type = type super().__init__(f'You are on cooldown. Try again in {retry_after:.2f}s') class MaxConcurrencyReached(CommandError): |