Enum serenity::model::ModelError [] [src]

pub enum ModelError {
    BulkDeleteAmount,
    DeleteMessageDaysAmount(u8),
    EmbedTooLarge(u64),
    GuildNotFound,
    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::*;
use serenity::Error;
use serenity::model::ModelError;
use std::env;

struct Handler;

impl EventHandler for Handler {
    fn on_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(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); client.start()?;

Variants

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

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

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

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

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

The provided Permissions is the set of required permissions required.

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

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

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.

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]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Error
[src]

[src]

Formats the value using the given formatter.

impl Eq for Error
[src]

impl Hash for Error
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

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

impl PartialEq for Error
[src]

[src]

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

[src]

This method tests for !=.

impl Display for Error
[src]

[src]

Formats the value using the given formatter. Read more

impl StdError for Error
[src]

[src]

A short description of the error. Read more

1.0.0
[src]

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