Struct discord::Discord [] [src]

pub struct Discord { /* 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]

Deprecated

: Login automation is not recommended. Use from_user_token instead.

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

Deprecated

: Login automation is not recommended. Use from_user_token instead.

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.

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

The token will automatically be prefixed with "Bot ".

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

Deprecated

: Accomplishes nothing and may fail for no reason.

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

Create a channel.

Get the list of channels in a server.

Get information about a channel.

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!")
);

Delete a channel.

Indicate typing on a channel for the next 5 seconds.

Get a single message by ID from a given channel.

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.

Gets the pinned messages for a given channel.

Pin the given message to the given channel.

Requires that the logged in account have the "MANAGE_MESSAGES" permission.

Removes the given message from being pinned to the given channel.

Requires that the logged in account have the "MANAGE_MESSAGES" permission.

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.

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.

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.

Bulk deletes a list of MessageIds 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.

Send some embedded rich content attached to a message on a given channel.

See the EmbedBuilder struct for the editable fields. text may be empty.

Edit the embed portion of a previously posted message.

The text is unmodified, but the previous embed is entirely replaced.

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.

Acknowledge this message as "read" by this client.

Create permissions for a Channel for a Member or Role.

Examples

An example of creating channel role permissions for a Member:

use discord::model::{PermissionOverwriteType, permissions};

// Assuming that a `Discord` instance, member, and channel have already
// been defined previously.
let target = PermissionOverwrite {
    kind: PermissionOverwriteType::Member(member.user.id),
    allow: permissions::VOICE_CONNECT | permissions::VOICE_SPEAK,
    deny: permissions::VOICE_MUTE_MEMBERS | permissions::VOICE_MOVE_MEMBERS,
};
let result = discord.create_permission(channel.id, target);

The same can similarly be accomplished for a Role:

use discord::model::{PermissionOverwriteType, permissions};

// Assuming that a `Discord` instance, role, and channel have already
// been defined previously.
let target = PermissionOverwrite {
    kind: PermissionOverwriteType::Role(role.id),
    allow: permissions::VOICE_CONNECT | permissions::VOICE_SPEAK,
    deny: permissions::VOICE_MUTE_MEMBERS | permissions::VOICE_MOVE_MEMBERS,
};
let result = discord.create_permission(channel.id, target);

Delete a Member or Role's permissions for a Channel.

Examples

Delete a Member's permissions for a Channel:

use discord::model::PermissionOverwriteType;

// Assuming that a `Discord` instance, channel, and member have already
// been previously defined.
let target = PermissionOverwriteType::Member(member.user.id);
let response = discord.delete_permission(channel.id, target);

The same can be accomplished for a Role similarly:

use discord::model::PermissionOverwriteType;

// Assuming that a `Discord` instance, channel, and role have already
// been previously defined.
let target = PermissionOverwriteType::Role(role.id);
let response = discord.delete_permission(channel.id, target);

Add a Reaction to a Message.

Examples

Add an unicode emoji to a Message:

// Assuming that a `Discord` instance, channel, message have
// already been previously defined.
use discord::model::ReactionEmoji;

let _ = discord.add_reaction(&channel.id, message.id, ReactionEmoji::Unicode("👌".to_string));

Add a custom emoji to a Message:

// Assuming that a `Discord` instance, channel, message have
// already been previously defined.
use discord::model::{EmojiId, ReactionEmoji};

let _ = discord.add_reaction(&channel.id, message.id, ReactionEmoji::Custom {
    name: "ThisIsFine",
    id: EmojiId(1234)
});

Requires the ADD_REACTIONS permission.

Delete a Reaction from a Message.

Examples

Delete a Reaction from a Message (unicode emoji):

// Assuming that a `Discord` instance, channel, message, state have
// already been previously defined.
use discord::model::ReactionEmoji;

let _ = discord.delete_reaction(&channel.id, message.id, None, ReactionEmoji::Unicode("👌".to_string()));

Delete your Reaction from a Message (custom emoji):

// Assuming that a `Discord` instance, channel, message have
// already been previously defined.
use discord::model::ReactionEmoji;

let _ = discord.delete_reaction(&channel.id, message.id, None, ReactionEmoji::Custom {
    name: "ThisIsFine",
    id: EmojiId(1234)
});

Delete someone else's Reaction from a Message (custom emoji):

// Assuming that a `Discord` instance, channel, message have
// already been previously defined.
use discord::model::{EmojiId, ReactionEmoji};

let _ = discord.delete_reaction(&channel.id, message.id, Some(UserId(1234)), ReactionEmoji::Custom {
    name: "ThisIsFine",
    id: EmojiId(1234)
});

Requires MANAGE_MESSAGES if deleting someone else's Reaction.

Get reactors for the Emoji in a Message.

The default limit is 50. The optional value of after is the ID of the user to retrieve the next reactions after.

Get the list of servers this user knows about.

Create a new server with the given name.

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")
);

Leave the given server.

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

Creates an emoji in a server.

read_image may be used to build an image string. Requires that the logged in account be a user and have the ADMINISTRATOR or MANAGE_EMOJIS permission.

Edits a server's emoji.

Requires that the logged in account be a user and have the ADMINISTRATOR or MANAGE_EMOJIS permission.

Delete an emoji in a server.

Requires that the logged in account be a user and have the ADMINISTRATOR or MANAGE_EMOJIS permission.

Get the ban list for the given server.

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

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

Unban a user from the server.

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.

Get the active invites for a server.

Get the active invites for a channel.

Accept an invite. See get_invite for details.

Create an invite to a channel.

Passing 0 for max_age or max_uses means no limit. max_age should be specified in seconds.

Delete an invite. See get_invite for details.

Retrieve a member object for a server given the member's user id.

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

Edit member information, including roles, nickname, and voice state.

See the EditMember struct for the editable fields.

Kick a member from a server.

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

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

Download a user's avatar.

Get the logged-in user's profile.

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

Usable for bot and user accounts. Only allows updating the username and avatar.

Edit the logged-in non-bot user's profile. See EditUserProfile for editable fields.

Usable only for user (non-bot) accounts. Requires mutable access in order to keep the login token up to date in the event of a password change.

Get the list of available voice regions for a server.

Move a server member to another voice channel.

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.

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.

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.

Retrieves information about the application and the owner.

Retrieves the number of guild shards Discord suggests to use based on the number of guilds.

This endpoint is only available for bots.

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.

See connect_sharded if you want to use guild sharding.

Establish a sharded websocket connection over which events can be received.

The shard_id is indexed at 0 while total_shards is indexed at 1.

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

See connect if you do not want to use guild sharding.