[−][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.
Implementations
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().await; if let Some(route) = reader.get(&Route::ChannelsId(7)) { if let Some(reset) = route.lock().await.reset() { println!("Reset time at: {:?}", reset); } }
pub async fn perform<'_, '_>(
&'_ self,
req: RatelimitedRequest<'_>
) -> Result<Response>
[src]
&'_ self,
req: RatelimitedRequest<'_>
) -> Result<Response>
Trait Implementations
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,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[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.
pub 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.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
pub fn vzip(self) -> V
impl<T> WithSubscriber for T
[src]
pub fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
S: Into<Dispatch>,