[][src]Enum serenity::model::error::Error

pub enum Error {
    BulkDeleteAmount,
    DeleteMessageDaysAmount(u8),
    EmbedTooLarge(u64),
    GuildNotFound,
    Hierarchy,
    InvalidPermissions(Permissions),
    InvalidUser,
    ItemMissing,
    MessageTooLong(u64),
    MessagingBot,
}

An error returned from the model module.

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

Examples

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

use serenity::prelude::*;
use serenity::model::prelude::*;
use serenity::Error;
use serenity::model::ModelError;
use std::env;

struct Handler;

impl EventHandler for Handler {
    fn guild_ban_removal(&self, context: Context, guild_id: GuildId, user: User) {
        // If the user has an even discriminator, don't re-ban them.
        if user.discriminator % 2 == 0 {
            return;
        }

     match guild_id.ban(user, &8) {
            Ok(()) => {
                // Ban successful.
            },
            Err(Error::Model(ModelError::DeleteMessageDaysAmount(amount))) => {
                println!("Failed deleting {} days' worth of messages", amount);
            },
            Err(why) => {
                println!("Unexpected error: {:?}", why);
            },
        }
    }
}
let token = env::var("DISCORD_BOT_TOKEN")?;
let mut client = Client::new(&token, Handler).unwrap();

client.start()?;

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.

Indicates that the textual content of an embed exceeds the maximum length.

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

Indicates that there are hierarchy problems restricting an action.

For example, when banning a user, if the other user has a role with an equal to or higher position, then they can not be banned.

When editing a role, if the role is higher in position than the current user's highest role, then the role can not be edited.

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 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.

Indicates that the current user is attempting to Direct Message another bot user, which is disallowed by the API.

Trait Implementations

impl PartialEq<Error> for Error
[src]

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

This method tests for !=.

impl From<Error> for Error
[src]

Performs the conversion.

impl Clone for Error
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Eq for Error
[src]

impl Debug for Error
[src]

Formats the value using the given formatter. Read more

impl Display for Error
[src]

Formats the value using the given formatter. Read more

impl Hash for Error
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl Error for Error
[src]

This method is soft-deprecated. Read more

Deprecating in 1.33.0

: replaced by Error::source, which can support downcasting

The lower-level cause of this error, if any. Read more

The lower-level source of this error, if any. Read more

Auto Trait Implementations

impl Send for Error

impl Sync for Error

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

Converts the given value to a String. Read more

impl<T> ToOwned for T where
    T: Clone
[src]

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T> Erased for T

impl<T> Typeable for T where
    T: Any

Get the TypeId of this object.

impl<T> DebugAny for T where
    T: Any + Debug
[src]

impl<T> CloneAny for T where
    T: Clone + Any
[src]

impl<T> UnsafeAny for T where
    T: Any