DynamicCooldown
Class
Cooldown whose duration is computed on every call.
from discord_interactions import DynamicCooldownExtends 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,)| Name | Type | Default | Description |
|---|---|---|---|
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 | Function (interaction) -> seconds. |
Properties
| Name | Type | Description |
|---|---|---|
rate | int | |
per | float | |
type | CooldownType | |
bucket_key | Callable[[discord.Interaction], str] | None |
Methods
per_func
def per_func()apply
def apply(func: Callable) -> Callableacquire
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) -> Nonereset
async def reset(interaction: discord.Interaction) -> Nonereset_all
def reset_all() -> Noneretry_after
def retry_after(interaction: discord.Interaction) -> floatExample
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): ...