#[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
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
RoleNotFound
MemberNotFound
ChannelNotFound
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
Indicates that you do not have the required permissions to perform an operation.
Fields
required: Permissions
Which permissions were required for the operation
present: Permissions
Which permissions the bot had
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 Message
s 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§
Trait Implementations§
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<Error> for Error
impl From<Error> for Error
Source§fn from(e: ModelError) -> Error
fn from(e: ModelError) -> Error
impl Eq for Error
impl StructuralPartialEq for Error
Auto Trait Implementations§
impl Freeze for Error
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.