Expand description
§djs-rest
A rate-limit-aware client for the Discord REST API, built on hyper — part of djs-rs.
Status: alpha. Every Discord API v10 endpoint a bot or an app uses (232 routes; not the deprecated ones or the Slack- and GitHub-compatible webhooks), with rate limiting, retries, file uploads, CDN URLs and OAuth2. The API may still change between alpha releases; see the changelog.
discord.js counterpart: @discordjs/rest
§Highlights
- hyper 1.x + rustls (ring, webpki-roots). HTTP/2 is negotiated automatically, so concurrent requests are multiplexed over one connection.
- Rate limits handled for you. Per-bucket sequential queues keyed by
X-RateLimit-Bucketand the major parameter, a global limit (50/s by default), global pauses on global 429s, and automatic retries — the same model as@discordjs/rest. - Retries and timeouts. Server errors, transport errors and timeouts are retried (3 times by default); every attempt is bounded by a timeout (15 s by default).
- Cheap to clone. Clones share the connection pool and rate-limit state.
- Observable. Every request emits
tracingevents; rate-limit hits are logged atwarn.
§Example
use djs_model::{id::ChannelId, rest::CreateMessage};
use djs_rest::Rest;
let rest = Rest::new(std::env::var("DISCORD_TOKEN").unwrap());
let message = rest
.create_message(ChannelId::new(1_234_567_890_123_456_789), &CreateMessage::from("Hello!"))
.await?;
println!("sent message {}", message.id);§Cargo features
| Feature | Default | Description |
|---|---|---|
hyper | ✓ | The default transport: hyper with rustls. Without it, set a Transport with RestBuilder::transport (for example fetch on Cloudflare Workers, wasm32-unknown-unknown) |
native-roots | Also trust the operating system’s root certificates (e.g. a corporate proxy’s CA), in addition to the bundled Mozilla roots |
§Part of djs-rs
djs-rest is one crate of djs-rs, a high-performance
Rust library for building Discord bots modelled on discord.js v14. It can be used on its own
(for example in HTTP-only interaction bots) or through the main djs-rs crate.
§License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Modules§
- cdn
- CDN URLs of avatars, icons, banners, emojis, stickers and other images (D-137).
- oauth2
- OAuth2 helpers: the client credentials of an application (D-132) and authorization URLs (D-133).
Structs§
- ApiError
- The JSON error body Discord returns with 4xx responses.
- Body
- The body of a request a
Transportsends: a sequence of byte chunks. - Error
- An error returned by
Rest. - Field
Error - An error of one field of a request body, from the
errorsof anApiError(D-099). - Request
- A request to send with
Rest::request. - Rest
- A client for the Discord REST API.
- Rest
Builder - Configures and builds a
Restclient.
Enums§
- Error
Kind - The kind of an
Error. - Reaction
Emoji - The emoji of a reaction endpoint (D-103), written into the path percent-encoded.
- Route
- A Discord REST API endpoint together with its path parameters.
Constants§
- DEFAULT_
API - The default API base URL.