discord-interactions.py

DynamicCooldown

Class

Cooldown whose duration is computed on every call.

from discord_interactions import DynamicCooldown

Extends CooldownBucket

Constructor

DynamicCooldown(    rate: int = 1,    per: float = 5.0,    type: CooldownType = CooldownType.USER,    bucket_key: Callable[[discord.Interaction], str] | None = None,    per_func: Callable[[discord.Interaction], float] = lambda,)
NameTypeDefaultDescription
rateint1
perfloat5.0
typeCooldownTypeCooldownType.USER
bucket_keyCallable[[discord.Interaction], str] | NoneNone
per_funcCallable[[discord.Interaction], float]lambdaFunction (interaction) -> seconds.

Properties

NameTypeDescription
rateint
perfloat
typeCooldownType
bucket_keyCallable[[discord.Interaction], str] | None

Methods

per_func

def per_func()

apply

def apply(func: Callable) -> Callable

acquire

def acquire(interaction: discord.Interaction) -> Tuple[bool, float]

check

async def check(interaction: discord.Interaction) -> Tuple[bool, float]

trigger

async def trigger(interaction: discord.Interaction) -> None

reset

async def reset(interaction: discord.Interaction) -> None

reset_all

def reset_all() -> None

retry_after

def retry_after(interaction: discord.Interaction) -> float

Example

from discord_interactions.slash import DynamicCooldown def duree(interaction):    return 5.0 if est_premium(interaction.user.id) else 30.0 @slash.command(description="Génération")@DynamicCooldown(rate=1, per_func=duree)async def generer(ctx):    ...

Details

def duree(interaction):

return 1.0 if est_premium(interaction.user.id) else 10.0

@slash.command() @DynamicCooldown(rate=1, per_func=duree) async def ia(ctx): ...

Type a name: create_button, ModalBuilder, cooldown.