Struct serenity::http::ratelimiting::Ratelimiter[][src]

pub struct Ratelimiter { /* fields omitted */ }
Expand description

Ratelimiter for requests to the Discord API.

This keeps track of ratelimit data for known routes through the Ratelimit implementation for each route: how many tickets are remaining until the user needs to wait for the known reset time, and the limit of requests that can be made within that time.

When no tickets are available for some time, then the thread sleeps until that time passes. The mechanism is known as “pre-emptive ratelimiting”.

Occasionally for very high traffic bots, a global ratelimit may be reached which blocks all future requests until the global ratelimit is over, regardless of route. The value of this global ratelimit is never given through the API, so it can’t be pre-emptively ratelimited. This only affects the largest of bots.

Implementations

Creates a new ratelimiter, with a shared reqwest client and the bot’s token.

The bot token must be prefixed with "Bot ". The ratelimiter does not prefix it.

The routes mutex is a HashMap of each Route and their respective ratelimit information.

See the documentation for Ratelimit for more information on how the library handles ratelimiting.

Examples

View the reset time of the route for ChannelsId(7):

use serenity::http::ratelimiting::Route;

let routes = http.ratelimiter.routes();
let reader = routes.read().await;

if let Some(route) = reader.get(&Route::ChannelsId(7)) {
    if let Some(reset) = route.lock().await.reset() {
        println!("Reset time at: {:?}", reset);
    }
}
Errors

Only error kind that may be returned is Error::Http.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more