Decorator Usage#

You have two choices for decorators, as documented below.

For example usages, view the examples section.

cooldowns.cooldown(limit: int, time_period: ~typing.Union[float, ~datetime.timedelta], bucket: ~cooldowns.protocols.bucket.CooldownBucketProtocol, check: ~typing.Optional[~typing.Callable[[~typing.Any, ~typing.Any], ~typing.Coroutine[~typing.Any, ~typing.Any, ~typing.Any]]] = <function default_check>, *, cooldown_id: ~typing.Optional[~typing.Union[int, str]] = None)#

Wrap this Callable in a cooldown.

Parameters
  • limit (int) – How many call’s can be made in the time period specified by time_period

  • time_period (Union[float, datetime.timedelta]) – The time period related to limit. This is seconds.

  • bucket (CooldownBucketProtocol) – The Bucket implementation to use as a bucket to separate cooldown buckets.

  • check (Optional[MaybeCoro]) –

    A Callable which dictates whether to apply the cooldown on current invoke.

    If this Callable returns a truthy value, then the cooldown will be used for the current call.

    I.e. If you wished to bypass cooldowns, you would return False if you invoked the Callable.

    Note

    This check will be given the same arguments as the item you are applying the cooldown to.

  • cooldown_id (Optional[Union[int, str]]) – Useful for resetting individual stacked cooldowns. This should be unique globally, behaviour is not guaranteed if not unique.

Raises
cooldowns.shared_cooldown(cooldown_id: Optional[Union[int, str]])#

Wrap this Callable in a shared cooldown.

Use define_shared_cooldown() before this.

Parameters

cooldown_id (Optional[Union[int, str]]) – The cooldown for the registered shared cooldown.

Raises
  • RuntimeError – Expected the decorated function to be a coroutine

  • CallableOnCooldown – This call resulted in a cooldown being put into effect

  • NonExistent – Could not find a cooldown with this ID registered.