Cooldowns¶
discord_http.cooldowns module¶
- class discord_http.cooldowns.BucketType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
- category = 4¶
- channel = 5¶
- default = 0¶
- guild = 3¶
- member = 2¶
- user = 1¶
- class discord_http.cooldowns.Cooldown(rate: int, per: float)[source]¶
Bases:
object
- get_retry_after(current: float | None = None) float [source]¶
Gets the time left before the cooldown resets.
- Parameters:
current (Optional[float]) – The current time to check the retry after for.
- Returns:
Time left before the cooldown resets.
- Return type:
float
- get_tokens(current: float | None = None) int [source]¶
Gets the amount of tokens available for the current time.
- Parameters:
current (Optional[float]) – The current time to check the tokens for.
- Returns:
Amount of tokens available.
- Return type:
int
- update_rate_limit(current: float | None = None, *, tokens: int = 1) float | None [source]¶
Updates the rate limit for the current time.
- Parameters:
current (Optional[float]) – The current time to update the rate limit for.
tokens (int) – Amount of tokens to remove from the rate limit.
- Returns:
Time left before the cooldown resets. Returns None if the rate limit was not exceeded.
- Return type:
Optional[float]
- class discord_http.cooldowns.CooldownCache(original: Cooldown, type: BucketType)[source]¶
Bases:
object
- get_bucket(ctx: Context, current: float | None = None) Cooldown [source]¶
Gets the cooldown bucket for the given context.
- Parameters:
ctx (Context) – Context to get the bucket for.
current (Optional[float]) – Current time to check the bucket for.
- Returns:
Cooldown bucket for the context.
- Return type:
Cooldown
- update_rate_limit(ctx: Context, current: float | None = None, *, tokens: int = 1) float | None [source]¶
Updates the rate limit for the given context.
- Parameters:
ctx (Context) – Context to update the rate limit for.
current (Optional[float]) – Current time to update the rate limit for.
tokens (int) – Amount of tokens to remove from the rate limit.
- Returns:
Time left before the cooldown resets. Returns None if the rate limit was not exceeded.
- Return type:
Optional[float]