Browse Source

[commands] Add back CommandOnCooldown.type

pull/7154/head
Rapptz 4 years ago
parent
commit
a3d7e06f25
  1. 4
      discord/ext/commands/cooldowns.py
  2. 2
      discord/ext/commands/core.py
  3. 9
      discord/ext/commands/errors.py

4
discord/ext/commands/cooldowns.py

@ -148,6 +148,10 @@ class CooldownMapping:
def valid(self): def valid(self):
return self._cooldown is not None return self._cooldown is not None
@property
def type(self):
return self._type
@classmethod @classmethod
def from_cooldown(cls, rate, per, type): def from_cooldown(cls, rate, per, type):
return cls(Cooldown(rate, per), type) return cls(Cooldown(rate, per), type)

2
discord/ext/commands/core.py

@ -731,7 +731,7 @@ class Command(_BaseCommand):
if bucket is not None: if bucket is not None:
retry_after = bucket.update_rate_limit(current) retry_after = bucket.update_rate_limit(current)
if retry_after: if retry_after:
raise CommandOnCooldown(bucket, retry_after) raise CommandOnCooldown(bucket, retry_after, self._buckets.type)
async def prepare(self, ctx): async def prepare(self, ctx):
ctx.command = self ctx.command = self

9
discord/ext/commands/errors.py

@ -460,14 +460,17 @@ class CommandOnCooldown(CommandError):
Attributes Attributes
----------- -----------
cooldown: ``Cooldown`` cooldown: ``Cooldown``
A class with attributes ``rate``, ``per``, and ``type`` similar to A class with attributes ``rate`` and ``per`` similar to the
the :func:`.cooldown` decorator. :func:`.cooldown` decorator.
type: :class:`BucketType`
The type associated with the cooldown.
retry_after: :class:`float` retry_after: :class:`float`
The amount of seconds to wait before you can retry again. 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.cooldown = cooldown
self.retry_after = retry_after self.retry_after = retry_after
self.type = type
super().__init__(f'You are on cooldown. Try again in {retry_after:.2f}s') super().__init__(f'You are on cooldown. Try again in {retry_after:.2f}s')
class MaxConcurrencyReached(CommandError): class MaxConcurrencyReached(CommandError):

Loading…
Cancel
Save