pub struct HttpBuilder { /* private fields */ }
Expand description
A builder for the underlying Http
client that performs requests to Discord’s HTTP API
If you do not need to use a proxy or do not need to disable the rate limiter, you can use
Http::new
instead.
§Example
Create an instance of Http
with a proxy and rate limiter disabled
let http =
HttpBuilder::new("token").proxy("http://127.0.0.1:3000").ratelimiter_disabled(true).build();
Implementations§
Source§impl HttpBuilder
impl HttpBuilder
Sourcepub fn new(token: impl AsRef<str>) -> Self
pub fn new(token: impl AsRef<str>) -> Self
Construct a new builder to call methods on for the HTTP construction. The token
will
automatically be prefixed “Bot “ if not already.
Sourcepub fn application_id(self, application_id: ApplicationId) -> Self
pub fn application_id(self, application_id: ApplicationId) -> Self
Sets the application_id to use interactions.
Sourcepub fn token(self, token: impl AsRef<str>) -> Self
pub fn token(self, token: impl AsRef<str>) -> Self
Sets a token for the bot. If the token is not prefixed “Bot “, this method will automatically do so.
Sourcepub fn client(self, client: Client) -> Self
pub fn client(self, client: Client) -> Self
Sets the reqwest::Client
. If one isn’t provided, a default one will be used.
Sourcepub fn ratelimiter(self, ratelimiter: Ratelimiter) -> Self
pub fn ratelimiter(self, ratelimiter: Ratelimiter) -> Self
Sets the ratelimiter to be used. If one isn’t provided, a default one will be used.
Sourcepub fn ratelimiter_disabled(self, ratelimiter_disabled: bool) -> Self
pub fn ratelimiter_disabled(self, ratelimiter_disabled: bool) -> Self
Sets whether or not the ratelimiter is disabled. By default if this this not used, it is
enabled. In most cases, this should be used in conjunction with Self::proxy
.
Note: You should not disable the ratelimiter unless you have another form of rate
limiting. Disabling the ratelimiter has the main purpose of delegating rate limiting to an
API proxy via Self::proxy
instead of the current process.
Sourcepub fn proxy(self, proxy: impl Into<String>) -> Self
pub fn proxy(self, proxy: impl Into<String>) -> Self
Sets the proxy that Discord HTTP API requests will be passed to. This is mainly intended
for something like twilight-http-proxy
where multiple processes can make API requests
while sharing a single ratelimiter.
The proxy should be in the form of the protocol and hostname, e.g. http://127.0.0.1:3000
or http://myproxy.example
This will simply send HTTP API requests to the proxy instead of Discord API to allow the
proxy to intercept, rate limit, and forward requests. This is different than a native
proxy’s behavior where it will tunnel requests that use TLS via HTTP CONNECT
method
(e.g. using reqwest::Proxy
).
Sourcepub fn default_allowed_mentions(
self,
allowed_mentions: CreateAllowedMentions,
) -> Self
pub fn default_allowed_mentions( self, allowed_mentions: CreateAllowedMentions, ) -> Self
Sets the CreateAllowedMentions
used by default for each request that would use it.
This only takes effect if you are calling through the model or builder methods, not directly
calling Http
methods, as Http
is simply used as a convenient storage for these.