Cooldowns

discord_http.cooldowns module

class discord_http.cooldowns.BucketType(value)

Bases: BaseEnum

category = 4
channel = 5
default = 0
get_key(ctx) int | tuple[int, int]

Returns the key for the bucket.

Parameters:

ctx (Context) – The bot context

Return type:

int | tuple[int, int]

Returns:

The key for the bucket

guild = 3
member = 2
user = 1
class discord_http.cooldowns.Cooldown(rate, per)

Bases: object

Parameters:
copy() Cooldown

Copies the cooldown.

Return type:

Cooldown

get_retry_after(current=None) float

Gets the time left before the cooldown resets.

Parameters:

current (float | None) – The current time to check the retry after for.

Return type:

float

Returns:

Time left before the cooldown resets.

get_tokens(current=None) int

Gets the amount of tokens available for the current time.

Parameters:

current (float | None) – The current time to check the tokens for.

Return type:

int

Returns:

Amount of tokens available.

reset() None

Resets the rate limit.

Return type:

None

update_rate_limit(current=None, *, tokens=1) float | None

Updates the rate limit for the current time.

Parameters:
  • current (float | None) – The current time to update the rate limit for.

  • tokens (int) – Amount of tokens to remove from the rate limit.

Return type:

float | None

Returns:

Time left before the cooldown resets. Returns None if the rate limit was not exceeded.

class discord_http.cooldowns.CooldownCache(original, type)

Bases: object

Parameters:
create_bucket() Cooldown

Creates a new cooldown bucket.

Return type:

Cooldown

get_bucket(ctx, current=None) Cooldown

Gets the cooldown bucket for the given context.

Parameters:
  • ctx (Context) – Context to get the bucket for.

  • current (float | None) – Current time to check the bucket for.

Return type:

Cooldown

Returns:

Cooldown bucket for the context.

update_rate_limit(ctx, current=None, *, tokens=1) float | None

Updates the rate limit for the given context.

Parameters:
  • ctx (Context) – Context to update the rate limit for.

  • current (float | None) – Current time to update the rate limit for.

  • tokens (int) – Amount of tokens to remove from the rate limit.

Return type:

float | None

Returns:

Time left before the cooldown resets. Returns None if the rate limit was not exceeded.