Enum serenity::client::ClientError
[−]
[src]
pub enum ClientError { BulkDeleteAmount, DeleteMessageDaysAmount(u8), ErrorCode(ErrorCode), Gateway, GuildNotFound, InvalidOpCode, InvalidOperationAsBot, InvalidOperationAsUser, InvalidPermissions(Permissions), InvalidShards, InvalidToken, InvalidUser, ItemMissing, MessageTooLong(u64), NoChannelId, RateLimitI64, RateLimitUtf8, RecordNotFound, ShardBootFailure, ShardUnknown, UnexpectedChannelType(ChannelType), UnexpectedStatusCode(StatusCode), UnknownStatus(u16), }
An error returned from the Client
or the Context
, or model instance.
This is always wrapped within the library's generic Error::Client
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::client::{Client, ClientError}; use serenity::Error; use std::env; let token = env::var("DISCORD_BOT_TOKEN").unwrap(); let mut client = Client::login_bot(&token); client.on_member_unban(|context, guild_id, user| { let discriminator = user.discriminator.parse::<u16>().unwrap(); // If the user has an even discriminator, don't re-ban them. if discriminator % 2 == 0 { return; } match guild_id.ban(user, 8) { Ok(()) => { // Ban successful. }, Err(Error::Client(ClientError::DeleteMessageDaysAmount(amount))) => { println!("Failed deleting {} days' worth of messages", amount); }, Err(why) => { println!("Unexpected error: {:?}", why); }, } });
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.
ErrorCode(ErrorCode)
Gateway
When there was an error retrieving the gateway URI from the REST API.
GuildNotFound
InvalidOpCode
InvalidOperationAsBot
When attempting to perform an action which is only available to user accounts.
InvalidOperationAsUser
When attempting to perform an action which is only available to bot accounts.
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.
InvalidShards
An indicator that the shard data received from the gateway is invalid.
InvalidToken
When the token provided is invalid. This is returned when validating a
token through the validate_token
function.
InvalidUser
An indicator that the current user can not 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.
NoChannelId
When attempting to use a Context
helper method which requires a
contextual ChannelId
, but the current context is not appropriate for
the action.
RateLimitI64
When the decoding of a ratelimit header could not be properly decoded
into an i64
.
RateLimitUtf8
When the decoding of a ratelimit header could not be properly decoded from UTF-8.
RecordNotFound
When attempting to find a required record from the Cache could not be
found. This is required in methods such as Context::edit_role
.
ShardBootFailure
ShardUnknown
When the shard being retrieved from within the Client could not be
found after being inserted into the Client's internal vector of
Shard
s.
This can be returned from one of the options for starting one or multiple shards.
This should never be received.
UnexpectedChannelType(ChannelType)
When a function such as Context::edit_channel
did not expect the
received ChannelType
.
UnexpectedStatusCode(StatusCode)
When a status code was unexpectedly received for a request's status.
UnknownStatus(u16)
When a status is received, but the verification to ensure the response is valid does not recognize the status.
Trait Implementations
impl Clone for Error
[src]
fn clone(&self) -> Error
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Debug for Error
[src]
impl Eq for Error
[src]
impl Hash for Error
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0
Feeds a slice of this type into the state provided.