[−][src]Struct serenity::http::ratelimiting::Ratelimiter
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
impl !RefUnwindSafe for Ratelimiter
impl Send for Ratelimiter
impl Sync for Ratelimiter
impl Unpin for Ratelimiter
impl !UnwindSafe for Ratelimiter
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> UnsafeAny for T where
T: Any,
T: Any,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,