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

#[non_exhaustive]
pub enum Error {
Show variants BulkDeleteAmount, DeleteMessageDaysAmount(u8), EmbedTooLarge(usize), GuildNotFound, RoleNotFound, MemberNotFound, ChannelNotFound, MessageAlreadyCrossposted, CannotCrosspostMessage, Hierarchy, InvalidPermissions(Permissions), InvalidUser, ItemMissing, WrongGuild, MessageTooLong(usize), MessagingBot, InvalidChannelType, NameTooShort, NameTooLong, NotAuthor, NoTokenSet,
}
Expand description

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;

struct Handler;

#[serenity::async_trait]
impl EventHandler for Handler {
    async 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, user, 8).await {
            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 = std::env::var("DISCORD_BOT_TOKEN")?;
let mut client = Client::builder(&token).event_handler(Handler).await?;

client.start().await?;

Variants (Non-exhaustive)

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
BulkDeleteAmount
Expand description

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

DeleteMessageDaysAmount(u8)
Expand description

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

EmbedTooLarge(usize)
Expand description

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

GuildNotFound
Expand description

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

RoleNotFound
Expand description

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

MemberNotFound
Expand description

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

ChannelNotFound
Expand description

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

MessageAlreadyCrossposted
Expand description

An indication that a Message has already been crossposted, and cannot be crossposted twice.

CannotCrosspostMessage
Expand description

An indication that you cannot crosspost a Message.

For instance, you cannot crosspost a system message or a message coming from the crosspost feature.

Hierarchy
Expand description

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)
Expand description

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

The provided Permissions is the set of required permissions required.

InvalidUser
Expand description

An indicator that the current user cannot perform an action.

ItemMissing
Expand description

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

WrongGuild
Expand description

Indicates that a member, role or channel from the wrong Guild was provided.

MessageTooLong(usize)
Expand description

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

The number of code points larger than the limit is provided.

MessagingBot
Expand description

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

InvalidChannelType
Expand description

An indicator that the ChannelType cannot perform an action.

NameTooShort
Expand description

Indicates that the webhook name is under the 2 characters limit.

NameTooLong
Expand description

Indicates that the webhook name is over the 100 characters limit.

NotAuthor
Expand description

Indicates that the bot is not author of the message. This error is returned in private/direct channels.

NoTokenSet
Expand description

Indicates that the webhook token is missing.

Implementations

impl Error[src]

pub fn is_cache_err(&self) -> bool[src]

Return true if the model error is related to an item missing in the cache.

Trait Implementations

impl Clone for Error[src]

fn clone(&self) -> Error[src]

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

impl Debug for Error[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Display for Error[src]

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult[src]

Formats the value using the given formatter. Read more

impl Error for Error[src]

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

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

fn backtrace(&self) -> Option<&Backtrace>[src]

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

Returns a stack backtrace, if available, of where this error occurred. Read more

fn description(&self) -> &str1.0.0[src]

👎 Deprecated since 1.42.0:

use the Display impl or to_string()

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

👎 Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

impl From<Error> for Error[src]

fn from(e: ModelError) -> Error[src]

Performs the conversion.

impl Hash for Error[src]

fn hash<__H: Hasher>(&self, state: &mut __H)[src]

Feeds this value into the given Hasher. Read more

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 PartialEq<Error> for Error[src]

fn eq(&self, other: &Error) -> bool[src]

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

fn ne(&self, other: &Error) -> bool[src]

This method tests for !=.

impl Eq 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]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn equivalent(&self, key: &K) -> bool[src]

Compare self to key and return true if they are equal.

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

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

fn in_current_span(self) -> Instrumented<Self>[src]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 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> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

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

pub fn vzip(self) -> V