cooldown

Helpers for setting a cooldown on commands.

exception CommandOnCooldown(message, function, /, *args, **kwargs)[source]

Bases: CommandError, Generic[P, R]

Raised when a command is invoked while on cooldown.

__init__(message, function, /, *args, **kwargs)[source]
async call_without_cooldown()[source]

Run the command this cooldown blocked.

Return type:

TypeVar(R)

Returns:

The command’s return value.

P = ~P[source]

The command’s signature.

class R[source]

The command’s return value.

alias of TypeVar(‘R’)

block_duplicate_invocations(*, cooldown_duration=5, send_notice=False, args_preprocessor=None)[source]

Prevent duplicate invocations of a command with the same arguments in a channel for cooldown_duration seconds.

Parameters:
  • cooldown_duration (float) – Length of the cooldown in seconds.

  • send_notice (bool) – If True, notify the user about the cooldown with a reply.

  • args_preprocessor (Callable[[ParamSpec(P)], Iterable[object]] | None) – If specified, this function is called with the args and kwargs the function is called with, its return value is then used to check for the cooldown instead of the raw arguments.

Return type:

Callable[[Callable[[ParamSpec(P)], Awaitable[TypeVar(R)]]], Callable[[ParamSpec(P)], Awaitable[TypeVar(R)]]]

Returns:

A decorator that adds a wrapper which applies the cooldowns.

Warning

The created wrapper raises CommandOnCooldown when the command is on cooldown.