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

pub struct Ratelimiter { /* fields omitted */ }

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.

Methods

impl Ratelimiter[src]

pub fn new(client: Arc<Client>, token: impl Into<String>) -> Self[src]

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.

pub fn routes(&self) -> Arc<RwLock<HashMap<Route, Arc<Mutex<Ratelimit>>>>>[src]

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();

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

pub fn perform(&self, req: RatelimitedRequest) -> Result<Response>[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> UnsafeAny for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,