[][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(&context.http, 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

BulkDeleteAmount

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

DeleteMessageDaysAmount(u8)

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

EmbedTooLarge(u64)

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

GuildNotFound

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

Hierarchy

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.

InvalidPermissions(Permissions)

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

The provided Permissions is the set of required permissions required.

InvalidUser

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

ItemMissing

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

MessageTooLong(u64)

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.

MessagingBot

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

Trait Implementations

impl Clone for Error[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl From<Error> for Error[src]

impl Eq for Error[src]

impl PartialEq<Error> for Error[src]

impl Debug for Error[src]

impl Display for Error[src]

impl Hash for Error[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

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

impl Error for Error[src]

fn cause(&self) -> Option<&dyn Error>1.0.0[src]

Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

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

fn source(&self) -> Option<&(dyn Error + 'static)>1.30.0[src]

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

fn type_id(&self) -> TypeId where
    Self: 'static, 
1.34.0[src]

Gets the TypeId of self

Auto Trait Implementations

impl Send for Error

impl Sync for Error

Blanket Implementations

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

impl<T> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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

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

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

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> Erased for T

impl<E> Fail for E where
    E: 'static + Error + Send + Sync

fn name(&self) -> Option<&str>

Returns the "name" of the error. Read more

fn cause(&self) -> Option<&(dyn Fail + 'static)>

Returns a reference to the underlying cause of this failure, if it is an error that wraps other errors. Read more

fn backtrace(&self) -> Option<&Backtrace>

Returns a reference to the Backtrace carried by this failure, if it carries one. Read more

fn context<D>(self, context: D) -> Context<D> where
    D: Display + Send + Sync + 'static, 

Provides context for this failure. Read more

fn compat(self) -> Compat<Self>

Wraps this failure in a compatibility wrapper that implements std::error::Error. Read more

impl<T> AsFail for T where
    T: Fail, 

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Err = <U as TryFrom<T>>::Err

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