Struct RestClient

Source
pub struct RestClient {
    pub token: String,
    pub base_url: String,
    pub http: Client,
    /* private fields */
}
Expand description

The Main client which is used to interface with the various components of the Discord API.

Fields§

§token: String

The bot token for this user.

§base_url: String

The base URL of the client. This may be changed to accomodate an external proxy system.

§http: Client

Implementations§

Source§

impl RestClient

Source

pub fn new(token: String, using_ratelimiter: bool) -> Self

Creates a new REST client with the provided configuration. The second argument denotes whether or not to use the built-in rate limiter to rate limit requests to the Discord API. If you plan to use a distributed architecture, you will need an external ratelimiter to ensure ratelimis are kept across servers.

Source

pub fn set_proxy(self, url: String) -> Self

Enables support for routing all requests though an HTTP rate limiting proxy. If you plan on making distributed REST requests, an HTTP proxy is recommended for handling rate limits in a distributed manner.

Source

pub fn channel(&self, id: &Snowflake) -> ChannelView

Opens a ChannelView for the provided Channel snowflake.

Source

pub fn guild(&self, id: &Snowflake) -> GuildView

Opens a GuildView for the provided Guild snowflake.

Source

pub fn webhook(&self, id: &Snowflake) -> WebhookView

Opens a WebhookView for the provided Webhook snowflake.

Source

pub fn get_user( &self, id: &Snowflake, ) -> impl Future<Item = User, Error = Error>

Gets a User object for the provided snowflake.

Source

pub fn create_dm( &self, user: &Snowflake, ) -> impl Future<Item = Channel, Error = Error>

Opens a new DM channel with the user at the provided user ID.

Source

pub fn create_guild( &self, opts: CreateGuildOptions, ) -> impl Future<Item = Guild, Error = Error>

Creates a new guild, setting the current client user as owner. This endpoint may only be used for bots who are in less than 10 guilds.

Source

pub fn leave_guild( &self, id: &Snowflake, ) -> impl Future<Item = (), Error = Error>

Leaves the guild using the provided guild ID.

Source

pub fn get_voice_regions( &self, ) -> impl Future<Item = Vec<VoiceRegion>, Error = Error>

Modifies properties for the current user. Obtains a list of Discord voice regions.

Source

pub fn get_invite( &self, code: &str, member_counts: bool, ) -> impl Future<Item = Invite, Error = Error>

Obtains an invite object from Discord using the given code. The second argument denotes whether the invite should contain approximate member counts

Source

pub fn delete_invite( &self, code: &str, ) -> impl Future<Item = Invite, Error = Error>

Deletes this invite from the its parent channel. This requires that the client have the MANAGE_CHANNELS permission.

Source

pub fn request<T>( &self, endpt: Endpoint, ) -> Box<dyn Future<Item = T, Error = Error> + Send>
where T: DeserializeOwned + Send + 'static,

Makes an HTTP request to the provided Discord API endpoint. Depending on the ratelimiter status, the request may or may not be rate limited.

Source

pub fn request_empty( &self, endpt: Endpoint, ) -> Box<dyn Future<Item = (), Error = Error> + Send>

Similar to the above method, but does not attempt to deserialize a JSON payload from the request. Use this method if you are dealing with routes that return 204 (No content).

Trait Implementations§

Source§

impl Clone for RestClient

Source§

fn clone(&self) -> RestClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RestClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Err>

Source§

impl<T> Erased for T

Source§

impl<T> ErasedDestructor for T
where T: 'static,