[−][src]Enum serenity::model::error::Error
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; use std::env; struct Handler; impl EventHandler for Handler { 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.http, 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).unwrap(); client.start()?;
Variants
BulkDeleteAmount
When attempting to delete below or above the minimum and maximum allowed number of messages.
DeleteMessageDaysAmount(u8)
When attempting to delete a number of days' worth of messages that is not allowed.
EmbedTooLarge(u64)
Indicates that the textual content of an embed exceeds the maximum length.
GuildNotFound
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)
Indicates that you do not have the required permissions to perform an operation.
The provided Permission
s 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.
MessageTooLong(u64)
Indicates that a Message
s 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.
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.
Trait Implementations
impl Clone for Error
[src]
fn clone(&self) -> Error
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl From<Error> for Error
[src]
fn from(e: ModelError) -> Error
[src]
impl PartialEq<Error> for Error
[src]
impl Eq for Error
[src]
impl Display for Error
[src]
impl Debug for Error
[src]
impl Hash for Error
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Error for Error
[src]
fn description(&self) -> &str
[src]
fn cause(&self) -> Option<&dyn Error>
1.0.0[src]
replaced by Error::source, which can support downcasting
The lower-level cause of this error, if any. Read more
fn source(&self) -> Option<&(dyn Error + 'static)>
1.30.0[src]
The lower-level source of this error, if any. Read more
Auto Trait Implementations
impl Sync for Error
impl Send for Error
impl Unpin for Error
impl RefUnwindSafe for Error
impl UnwindSafe for Error
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> Erased for T
impl<E> Fail for E where
E: 'static + Error + Send + Sync,
E: 'static + Error + Send + Sync,
fn name(&self) -> Option<&str>
Returns the "name" of the error. Read more
fn cause(&self) -> Option<&(dyn Fail + 'static)>
Returns a reference to the underlying cause of this failure, if it is an error that wraps other errors. Read more
fn backtrace(&self) -> Option<&Backtrace>
Returns a reference to the Backtrace
carried by this failure, if it carries one. Read more
fn context<D>(self, context: D) -> Context<D> where
D: Display + Send + Sync + 'static,
D: Display + Send + Sync + 'static,
Provides context for this failure. Read more
fn compat(self) -> Compat<Self>
Wraps this failure in a compatibility wrapper that implements std::error::Error
. Read more
impl<T> AsFail for T where
T: Fail,
T: Fail,
fn as_fail(&self) -> &(dyn Fail + 'static)
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,
impl<T> DebugAny for T where
T: Any + Debug,
[src]
T: Any + Debug,
impl<T> CloneAny for T where
T: Clone + Any,
[src]
T: Clone + Any,
fn clone_any(&self) -> Box<dyn CloneAny + 'static>
[src]
fn clone_any_send(&self) -> Box<dyn CloneAny + 'static + Send> where
T: Send,
[src]
T: Send,
fn clone_any_sync(&self) -> Box<dyn CloneAny + 'static + Sync> where
T: Sync,
[src]
T: Sync,
fn clone_any_send_sync(&self) -> Box<dyn CloneAny + 'static + Send + Sync> where
T: Send + Sync,
[src]
T: Send + Sync,
impl<T> UnsafeAny for T where
T: Any,
T: Any,