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

#[non_exhaustive]
pub enum Error {
Show 23 variants BulkDeleteAmount, DeleteMessageDaysAmount(u8), EmbedAmount, EmbedTooLarge(usize), GuildNotFound, RoleNotFound, MemberNotFound, ChannelNotFound, MessageAlreadyCrossposted, CannotCrosspostMessage, Hierarchy, InvalidPermissions(Permissions), InvalidUser, ItemMissing, WrongGuild, MessageTooLong(usize), MessagingBot, InvalidChannelType, NameTooShort, NameTooLong, NotAuthor, NoTokenSet, InvalidComponentType,
}
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::model::prelude::*;
use serenity::model::ModelError;
use serenity::prelude::*;
use serenity::Error;

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

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

DeleteMessageDaysAmount(u8)

Tuple Fields

0: 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)

Tuple Fields

0: 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(Permissions)

Tuple Fields

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.

WrongGuild

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

MessageTooLong(usize)

Tuple Fields

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

InvalidComponentType

Indicates that the component type cannot be used in this context.

Implementations

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

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

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

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

👎 Deprecated since 1.42.0:

use the Display impl or to_string()

👎 Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Performs the conversion.

Feeds this value into the given Hasher. Read more

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

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

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

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

Performs the conversion.

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

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

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

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

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

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

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

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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