Enum serenity::model::error::Error

source ·
#[non_exhaustive]
pub enum Error {
Show 26 variants BulkDeleteAmount, DeleteMessageDaysAmount(u8), EmbedAmount, EmbedTooLarge(usize), GuildNotFound, RoleNotFound, MemberNotFound, ChannelNotFound, MessageAlreadyCrossposted, CannotCrosspostMessage, Hierarchy, InvalidPermissions { required: Permissions, present: Permissions, }, InvalidUser, ItemMissing, WrongGuild, MessageTooLong(usize), MessagingBot, InvalidChannelType, NameTooShort, NameTooLong, NotAuthor, NoTokenSet, DeleteNitroSticker, NoStickerFileSet, StickerAmount, CannotEditVoiceMessage,
}
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.

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


#[serenity::async_trait]
#[cfg(feature = "client")]
impl EventHandler for Handler {
    async fn guild_ban_removal(&self, context: Context, guild_id: GuildId, user: User) {
        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);
            },
        }
    }
}

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

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

§

DeleteMessageDaysAmount(u8)

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

§

EmbedAmount

When attempting to send a message with over 10 embeds.

§

EmbedTooLarge(usize)

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.

§

MemberNotFound

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

§

ChannelNotFound

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

§

MessageAlreadyCrossposted

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

§

CannotCrosspostMessage

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

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

Fields

§required: Permissions

Which permissions were required for the operation

§present: Permissions

Which permissions the bot had

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

§

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.

§

WrongGuild

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

§

MessageTooLong(usize)

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

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.

§

NameTooShort

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

§

NameTooLong

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

§

NotAuthor

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

§

NoTokenSet

Indicates that the webhook token is missing.

§

DeleteNitroSticker

When attempting to delete a built in nitro sticker instead of a guild sticker.

§

NoStickerFileSet

Indicates that the sticker file is missing.

§

StickerAmount

When attempting to send a message with over 3 stickers.

§

CannotEditVoiceMessage

When attempting to edit a voice message.

Implementations§

source§

impl Error

source

pub const fn is_cache_err(&self) -> bool

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

Trait Implementations§

source§

impl Clone for Error

source§

fn clone(&self) -> Error

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Error

source§

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

Formats the value using the given formatter. Read more
source§

impl Display for Error

source§

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

Formats the value using the given formatter. Read more
source§

impl Error for Error

1.30.0 · source§

fn source(&self) -> Option<&(dyn Error + 'static)>

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

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type based access to context intended for error reports. Read more
source§

impl From<Error> for Error

source§

fn from(e: ModelError) -> Error

Converts to this type from the input type.
source§

impl Hash for Error

source§

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

Feeds this value into the given Hasher. Read more
1.3.0 · source§

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

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for Error

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Error

source§

impl StructuralPartialEq for Error

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneDebuggableStorage for T

source§

impl<T> CloneableStorage for T
where T: Any + Send + Sync + Clone,

§

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

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

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

§

fn equivalent(&self, key: &K) -> bool

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DebuggableStorage for T
where T: Any + Send + Sync + Debug,