Enum serenity::client::ClientError [] [src]

pub enum ClientError {
    BulkDeleteAmount,
    DeleteMessageDaysAmount(u8),
    Gateway,
    GuildNotFound,
    InvalidOpCode,
    InvalidOperationAsBot,
    InvalidOperationAsUser,
    InvalidPermissions(Permissions),
    InvalidShards,
    InvalidToken,
    InvalidUser,
    ItemMissing,
    MessageTooLong(u64),
    NoChannelId,
    RateLimitI64,
    RateLimitUtf8,
    RecordNotFound,
    ShardUnknown,
    UnexpectedChannelType(ChannelType),
    UnexpectedStatusCode(StatusCode),
    UnknownStatus(u16),
}

An error returned from the Client or the Context, or model instance.

This is always wrapped within the library's generic Error::Client variant.

Examples

Matching an [Error] with this variant may look something like the following for the [Client::ban] method, which in this example is used to re-ban all members with an odd discriminator:

use serenity::client::{Client, ClientError};
use serenity::Error;
use std::env;

let token = env::var("DISCORD_BOT_TOKEN").unwrap();
let mut client = Client::login_bot(&token);

client.on_member_unban(|context, guild_id, user| {
    let discriminator = user.discriminator.parse::<u16>().unwrap();

    // If the user has an even discriminator, don't re-ban them.
    if discriminator % 2 == 0 {
        return;
    }

    match context.ban(guild_id, user, 8) {
        Ok(()) => {
            // Ban successful.
        },
        Err(Error::Client(ClientError::DeleteMessageDaysAmount(amount))) => {
            println!("Failed deleting {} days' worth of messages", amount);
        },
        Err(why) => {
            println!("Unexpected error: {:?}", why);
        },
    }
});

Variants

When attempting to delete below or above the minimum and maximum allowed number of messages.

When attempting to delete a number of days' worth of messages that is not allowed.

When there was an error retrieving the gateway URI from the REST API.

An indication that a guild could not be found by Id in the Cache.

When attempting to perform an action which is only available to user accounts.

When attempting to perform an action which is only available to bot accounts.

Indicates that you do not have the required permissions to perform an operation.

The provided Permissions is the set of required permissions required.

An indicator that the shard data received from the gateway is invalid.

When the token provided is invalid. This is returned when validating a token through the validate_token function.

An indicator that the current user can not perform an action.

An indicator that an item is missing from the Cache, and the action can not be continued.

Indicates that a Messages content was too long and will not successfully send, as the length is over 2000 codepoints, or 4000 bytes.

The number of bytes larger than the limit is provided.

When attempting to use a Context helper method which requires a contextual ChannelId, but the current context is not appropriate for the action.

When the decoding of a ratelimit header could not be properly decoded into an i64.

When the decoding of a ratelimit header could not be properly decoded from UTF-8.

When attempting to find a required record from the Cache could not be found. This is required in methods such as Context::edit_role.

When the shard being retrieved from within the Client could not be found after being inserted into the Client's internal vector of Shards.

This can be returned from one of the options for starting one or multiple shards.

This should never be received.

When a function such as Context::edit_channel did not expect the received ChannelType.

When a status code was unexpectedly received for a request's status.

When a status is received, but the verification to ensure the response is valid does not recognize the status.

Trait Implementations

impl Clone for Error
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Error
[src]

Formats the value using the given formatter.

impl Eq for Error
[src]

impl Hash for Error
[src]

Feeds this value into the state given, updating the hasher as necessary.

Feeds a slice of this type into the state provided.

impl PartialEq for Error
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.