discord-interactions.py

cooldown

Function

Rate-limits a command: @cooldown(1, 5) allows one use every 5 seconds per user.

from discord_interactions import cooldown

Signature

def cooldown(    rate: int = 1,    per: float = 5.0,    type: CooldownType = CooldownType.USER,    bucket_key: Callable[[discord.Interaction], str] | None = None,) -> Callable

Parameters

NameTypeDefaultDescription
rateint1Number of uses in the window.
perfloat5.0Window length in seconds.
typeCooldownTypeCooldownType.USERScope: user, member, guild, channel, category, role, global or custom.
bucket_keyCallable[[discord.Interaction], str] | NoneNoneCustom key (interaction) -> str.

Returns

Callable

Example

from discord_interactions.slash import CooldownType, cooldown @slash.command(description="Récompense quotidienne")@cooldown(1, 86_400, type=CooldownType.MEMBER)async def quotidien(ctx):    await ctx.respond("+100 pièces")

Type a name: create_button, ModalBuilder, cooldown.