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

pub enum Error {
    BulkDeleteAmount,
    DeleteMessageDaysAmount(u8),
    EmbedTooLarge(u64),
    GuildNotFound,
    RoleNotFound,
    Hierarchy,
    InvalidPermissions(Permissions),
    InvalidUser,
    ItemMissing,
    MessageTooLong(u64),
    MessagingBot,
    InvalidChannelType,
    // some variants omitted
}

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.

RoleNotFound

An indication that a role 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 cannot 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.

InvalidChannelType

An indicator that the ChannelType cannot perform an action.

Trait Implementations

impl Clone for Error[src]

impl Debug for Error[src]

impl Display for Error[src]

impl Eq for Error[src]

impl Error for Error[src]

impl From<Error> for Error[src]

impl Hash for Error[src]

impl PartialEq<Error> for Error[src]

impl StructuralEq for Error[src]

impl StructuralPartialEq for Error[src]

Auto Trait Implementations

impl RefUnwindSafe for Error

impl Send for Error

impl Sync for Error

impl Unpin for Error

impl UnwindSafe for Error

Blanket Implementations

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

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

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

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

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

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

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

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

impl<T> Same<T> for T

type Output = T

Should always be Self

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

type Owned = T

The resulting type after obtaining ownership.

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

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> UnsafeAny for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,