RateLimitProxy

A proxy towards a rate limit.

Attributes

client : Client

Who's rate limits will be looked up.

The proxy's rate limit group to pull additional information.

_handler : None or ( WeakReferer to RateLimitHandler)

Reference to the actual rate limit handler of the client with the specified group and limiter.

RateLimit handler used to lookup the active one.

Properties

free_count

Returns how much requests can be done towards the represented rate limit.

If the rate limit proxy represents an unlimited endpoint, then 0 is returned.

Returns

free_count : int

handler

Returns the client's represented active handler if applicable.

Returns

handler : None, RateLimitHandler

keep_alive

Get-set property for accessing whether the rate limit proxy should keep alive the respective rate limit handler.

Accepts and returns bool.

limiter_id

Returns the the represented rate limit handler's .limiter_id.

Returns

limiter_id : int

next_reset_after

Familiar to .next_reset_at but it instead returns how time is left till next reset instead.

Returns

next_reset_after : float

next_reset_at

Returns when the next rate limit reset will happen of the represented rate limit handler.

If there is no active rate limit handler represented or if the handler has has 0 used up limits, then returns 0.0. if there is any, then returns it in LOOP_TIME time.

Returns

next_reset_at : float

size

Returns the represented rate limit group's size.

Returns

size : int

used_count

Returns how much requests are used up or already done right now.

Returns

count : int

waiting_count

Returns how much requests are waiting in queue by the represented rate limit.

Returns

count : int

Methods

__new__(client, group, ...)

Creates a new rate limit proxy.

ParameterTypeOptionalDefaultDescription
client

Client

Who's rate limits will be looked up.

group

RateLimitGroup

The proxy's rate limit group to pull additional information.

limiter

None, DiscordEntity

None

What's rate limits will be looked up.

The accepted types depend on the group's limiter:

Respective limiterAccepted values
LIMITER_CHANNELChannel, Message
LIMITER_GUILDGuild, Channel, Message, Role, Webhook, WebhookRepr
LIMITER_WEBHOOKWebhook, WebhookRepr
LIMITER_INTERACTIONInteractionEvent
LIMITER_GLOBALobject
LIMITER_UNLIMITEDobject

Note that at the case of LIMITER_GUILD partial objects will yield .guild as None so ValueError will still be raised.

keep_alive

bool

False

Whether the rate limit proxy should keep alive the respective rate limit handler. Defaults to False.

Raises

RuntimeError

If the given group 's limiter is not any of the predefined ones. Note that limiters are compared by memory address and not by value.

TypeError

If group was not given as RateLimitGroup.

ValueError

If the given limiter cannot be casted to limiter_id with the specified group.

has_info()

Returns whether the represented rate limit handler now stores any rate limit information.

Returns

has_info : bool

has_size_set()

Returns whether the represented rate limit group size is already set.

Not only not used rate limit groups, but still optimistic or unlimited rate limit groups fall under this category as well.

Returns

has_size_set : bool

is_alive()

Returns whether the respective client has the represented rate limit handler is alive.

Returns

is_alive : bool

is_limited_by_channel()

Returns whether the represented rate limit group is limited by channel id.

Returns

is_limited_by_channel : bool

is_limited_by_guild()

Returns whether the represented rate limit group is limited by guild id.

Returns

is_limited_by_guild : bool

is_limited_by_interaction()

Returns whether the represented rate limit group is limited by interaction id.

Returns

is_limited_by_interaction : bool

is_limited_by_webhook()

Returns whether the represented rate limit group is limited by webhook id.

Returns

is_limited_by_webhook : bool

is_limited_globally()

Returns whether the represented rate limit group is limited globally,

Returns

is_limited_globally : bool

is_unlimited()

Returns whether the represented rate limit group is unlimited,

Returns

is_unlimited : bool

wait_till_limits_expire()

Waits till the represented rate limits expire.

This method is a coroutine.

Raises

RuntimeError

If the method is called meanwhile keep_alive is True.

Notes

The waiting is implemented with weakreference callback, so the coroutine returns when the source callback is garbage collected. This also means waiting on the exact same limit multiple times causes misbehaviour.

__hash__()

Hashes the rate limit proxy.

Classes

_wait_till_limits_expire_callback

WeakReferer callback used at .wait_till_limits_expire for waking it up.

Attributes

future : Future

The future to set it's result of.

Methods

__init__()
__call__()