Struct dasi::Discord [] [src]

pub struct Discord {
    // some fields omitted
}

Client for the Discord REST API.

Log in to the API with a user's email and password using new(). Call connect() to create a Connection on which to receive events. If desired, use logout() to invalidate the token when done. Other methods manipulate the Discord REST API.

Methods

impl Discord

fn new(email: &str, password: &str) -> Result<Discord>

Log in to the Discord Rest API and acquire a token.

fn new_cache<P: AsRef<Path>>(path: P, email: &str, password: Option<&str>) -> Result<Discord>

Log in to the Discord Rest API, possibly using a cached login token.

Cached login tokens are keyed to the email address and will be read from and written to the specified path. If no cached token was found and no password was specified, an error is returned.

fn from_bot_token(token: &str) -> Result<Discord>

Log in as a bot account using the given authentication token.

fn logout(self) -> Result<()>

Log out from the Discord API, invalidating this clients's token.

fn create_channel(&self, server: &ServerId, name: &str, kind: ChannelType) -> Result<Channel>

Create a channel.

fn edit_channel(&self, channel: &ChannelId, name: Option<&str>, position: Option<i64>, topic: Option<&str>) -> Result<Channel>

Edit a channel's name.

fn delete_channel(&self, channel: &ChannelId) -> Result<Channel>

Delete a channel.

fn broadcast_typing(&self, channel: &ChannelId) -> Result<()>

Indicate typing on a channel for the next 5 seconds.

fn get_messages(&self, channel: &ChannelId, before: Option<&MessageId>, after: Option<&MessageId>, limit: Option<u64>) -> Result<Vec<Message>>

Get messages in the backlog for a given channel.

Before and after limits can be specified to narrow the results. A message count limit can also be specified, defaulting to 50. Newer messages appear first in the list.

fn send_message(&self, channel: &ChannelId, text: &str, nonce: &str, tts: bool) -> Result<Message>

Send a message to a given channel.

The nonce will be returned in the result and also transmitted to other clients. The empty string is a good default if you don't care.

fn edit_message(&self, channel: &ChannelId, message: &MessageId, text: &str) -> Result<Message>

Edit a previously posted message.

Requires that either the message was posted by this user, or this user has permission to manage other members' messages.

fn delete_message(&self, channel: &ChannelId, message: &MessageId) -> Result<()>

Delete a previously posted message.

Requires that either the message was posted by this user, or this user has permission to manage other members' messages.

fn send_file<R: Read>(&self, channel: &ChannelId, text: &str, file: R, filename: &str) -> Result<Message>

Send a file attached to a message on a given channel.

The text is allowed to be empty, but the filename must always be specified.

fn ack_message(&self, channel: &ChannelId, message: &MessageId) -> Result<()>

Acknowledge this message as "read" by this client.

fn get_servers(&self) -> Result<Vec<ServerInfo>>

Get the list of servers this user knows about.

fn create_server(&self, name: &str, region: &str, icon: Option<&str>) -> Result<Server>

Create a new server with the given name.

fn edit_server<F: FnOnce(EditServer) -> EditServer>(&self, server_id: ServerId, f: F) -> Result<Server>

Edit a server's information. See EditServer for the editable fields.

// Rename a server
discord.edit_server(server_id, |server| server.name("My Cool Server"));
// Edit many properties at once
discord.edit_server(server_id, |server| server
    .name("My Cool Server")
    .icon(Some("data:image/jpg;base64,..."))
    .afk_timeout(300)
    .region("us-south")
);

fn leave_server(&self, server: &ServerId) -> Result<Server>

Leave the given server.

fn delete_server(&self, server: &ServerId) -> Result<Server>

Delete the given server. Only available to the server owner.

fn get_bans(&self, server: &ServerId) -> Result<Vec<User>>

Get the ban list for the given server.

fn add_ban(&self, server: &ServerId, user: &UserId, delete_message_days: u32) -> Result<()>

Ban a user from the server, optionally deleting their recent messages.

Zero may be passed for delete_message_days if no deletion is desired.

fn remove_ban(&self, server: &ServerId, user: &UserId) -> Result<()>

Unban a user from the server.

fn get_invite(&self, invite: &str) -> Result<Invite>

Extract information from an invite.

The invite should either be a URL of the form http://discord.gg/CODE, or a string containing just the CODE.

fn get_server_invites(&self, server: ServerId) -> Result<Vec<RichInvite>>

Get the active invites for a server.

fn get_channel_invites(&self, channel: ChannelId) -> Result<Vec<RichInvite>>

Get the active invites for a channel.

fn accept_invite(&self, invite: &str) -> Result<Invite>

Accept an invite. See get_invite for details.

fn create_invite(&self, channel: ChannelId, max_age: u64, max_uses: u64, temporary: bool, xkcdpass: bool) -> Result<RichInvite>

Create an invite to a channel.

Passing 0 for max_age or max_uses means no limit. max_age should be specified in seconds. Enabling xkcdpass forces a 30-minute expiry.

fn delete_invite(&self, invite: &str) -> Result<Invite>

Delete an invite. See get_invite for details.

fn edit_member_roles(&self, server: &ServerId, user: &UserId, roles: &[&RoleId]) -> Result<()>

Edit the list of roles assigned to a member of a server.

fn kick_member(&self, server: &ServerId, user: &UserId) -> Result<()>

Kick a member from a server.

fn create_private_channel(&self, recipient: &UserId) -> Result<PrivateChannel>

Create a private channel with the given user, or return the existing one if it exists.

fn get_user_avatar_url(&self, user: &UserId, avatar: &str) -> String

Get the URL at which a user's avatar is located.

fn get_user_avatar(&self, user: &UserId, avatar: &str) -> Result<Vec<u8>>

Download a user's avatar.

fn edit_profile<F: FnOnce(EditProfile) -> EditProfile>(&mut self, f: F) -> Result<CurrentUser>

Edit the logged-in user's profile. See EditProfile for editable fields.

This method requires mutable access because editing the profile generates a new token.

fn get_voice_regions(&self) -> Result<Vec<VoiceRegion>>

Get the list of available voice regions for a server.

fn move_member_voice(&self, server: &ServerId, user: &UserId, channel: &ChannelId) -> Result<()>

Move a server member to another voice channel.

fn connect(&self) -> Result<(Connection, ReadyEvent)>

Establish a websocket connection over which events can be received.

Also returns the ReadyEvent sent by Discord upon establishing the connection, which contains the initial state as seen by the client.