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.
- 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_durationseconds.- Parameters:
cooldown_duration (
float) – Length of the cooldown in seconds.send_notice (
bool) – IfTrue, 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
CommandOnCooldownwhen the command is on cooldown.