Struct discord::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
[src]
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 get_channel(&self, channel: ChannelId) -> Result<Channel>
Get information about a channel.
fn edit_channel<F: FnOnce(EditChannel) -> EditChannel>(&self, channel: ChannelId, f: F) -> Result<PublicChannel>
Edit a channel's details. See EditChannel
for the editable fields.
// Edit a channel's name and topic discord.edit_channel(channel_id, "general", |ch| ch .topic("Welcome to the general chat!") );
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_message(&self, channel: ChannelId, message: MessageId) -> Result<Message>
Get a single message by ID from a given channel.
fn get_messages(&self, channel: ChannelId, what: GetMessages, limit: Option<u64>) -> Result<Vec<Message>>
Get messages in the backlog for a given channel.
The what
argument should be one of the options in the GetMessages
enum, and will determine which messages will be returned. A message
limit can also be specified, and defaults to 50. More recent messages
will appear first in the list.
fn get_pinned_messages(&self, channel: ChannelId) -> Result<Vec<Message>>
Gets the pinned messages for a given channel.
fn pin_message(&self, channel: ChannelId, message: MessageId) -> Result<()>
Pin the given message to the given channel.
Requires that the logged in account have the "MANAGE_MESSAGES" permission.
fn unpin_message(&self, channel: ChannelId, message: MessageId) -> Result<()>
Removes the given message from being pinned to the given channel.
Requires that the logged in account have the "MANAGE_MESSAGES" permission.
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 delete_messages(&self, channel: ChannelId, messages: &[MessageId]) -> Result<()>
Bulk deletes a list of MessageId
s from a given channel.
A minimum of 2 unique messages and a maximum of 100 unique messages may
be supplied, otherwise an Error::Other
will be returned.
Each MessageId should be unique as duplicates will be removed from the array before being sent to the Discord API.
Only bots can use this endpoint. Regular user accounts can not use this endpoint under any circumstance.
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 get_member(&self, server: ServerId, user: UserId) -> Result<Member>
Retrieve a member object for a server given the member's user id.
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 edit_member<F: FnOnce(EditMember) -> EditMember>(&self, server: ServerId, user: UserId, f: F) -> Result<()>
Edit member information, including roles, nickname, and voice state.
See the EditMember
struct for the editable fields.
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 begin_server_prune(&self, server: ServerId, days: u16) -> Result<ServerPrune>
Start a prune operation, kicking members who have been inactive for the specified number of days. Members with a role assigned will never be pruned.
fn get_server_prune_count(&self, server: ServerId, days: u16) -> Result<ServerPrune>
Get the number of members who have been inactive for the specified number of days and would be pruned by a prune operation. Members with a role assigned will never be pruned.
fn edit_note(&self, user: UserId, note: &str) -> Result<()>
Sets a note for the user that is readable only to the currently logged in user.
This endpoint is only available for users, and so does not work for bots.
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.