DynamicCooldown
Classe
Cooldown dont la durée est calculée à chaque appel.
from discord_interactions import DynamicCooldownHérite de CooldownBucket
Constructeur
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,)| Nom | Type | Défaut | 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 | Fonction (interaction) -> secondes. |
Propriétés
| Nom | Type | Description |
|---|---|---|
rate | int | |
per | float | |
type | CooldownType | |
bucket_key | Callable[[discord.Interaction], str] | None |
Méthodes
per_func
def per_func()apply
def apply(func: Callable) -> Callableacquire
def acquire(interaction: discord.Interaction) -> Tuple[bool, float]Vérifie et consomme en une étape. Renvoie `(autorisé, attente_en_secondes)`.
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) -> floatExemple
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): ...