#[non_exhaustive]pub enum CloseCode {
Show 15 variants
UnknownError,
UnknownOpcode,
DecodeError,
NotAuthenticated,
AuthenticationFailed,
AlreadyAuthenticated,
InvalidSequence,
RateLimited,
SessionTimedOut,
InvalidShard,
ShardingRequired,
InvalidApiVersion,
InvalidIntents,
DisallowedIntents,
Unknown(u16),
}Expand description
A gateway close event code: the reason Discord gives when it closes the WebSocket connection.
Use CloseCode::can_reconnect to decide whether reconnecting is allowed.
discord.js counterpart: GatewayCloseCodes (re-exported from discord-api-types).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
UnknownError
Something went wrong on Discord’s side. Reconnecting is allowed.
UnknownOpcode
The client sent an invalid opcode or an invalid payload for an opcode.
DecodeError
The client sent a payload Discord could not decode.
NotAuthenticated
The client sent a payload before identifying, or the session was invalidated.
AuthenticationFailed
The token sent in the identify payload is incorrect. Do not reconnect.
AlreadyAuthenticated
The client sent more than one identify payload.
InvalidSequence
The sequence number sent when resuming was invalid. Reconnect and start a new session.
RateLimited
The client is sending payloads too quickly.
SessionTimedOut
The session timed out. Reconnect and start a new session.
InvalidShard
The client sent an invalid shard when identifying. Do not reconnect.
ShardingRequired
The session would have handled too many guilds; sharding is required. Do not reconnect.
InvalidApiVersion
The client requested an invalid gateway version. Do not reconnect.
InvalidIntents
The client sent an invalid intent bitfield. Do not reconnect.
DisallowedIntents
The client requested an intent it is not enabled or approved for (usually a privileged intent). Do not reconnect.
Unknown(u16)
A value that this version of the library does not know about.
Discord may add new values at any time. They are preserved here so that no
information is lost and deserialization never fails because of them. Prefer
CloseCode::from over constructing this variant directly.
Implementations§
Source§impl CloseCode
impl CloseCode
Sourcepub const fn value(self) -> u16
pub const fn value(self) -> u16
Returns the raw integer value Discord uses for this variant.
discord.js counterpart: the enum’s numeric value in discord-api-types.
Sourcepub const fn is_unknown(self) -> bool
pub const fn is_unknown(self) -> bool
Returns true if this is a value the library does not know about.
discord.js counterpart: none (discord.js passes unknown numbers through).
Sourcepub const fn from_value(value: u16) -> Self
pub const fn from_value(value: u16) -> Self
Converts a raw value into the matching variant, or Self::Unknown.
discord.js counterpart: none (discord.js passes unknown numbers through).
Source§impl CloseCode
impl CloseCode
Sourcepub const fn can_reconnect(self) -> bool
pub const fn can_reconnect(self) -> bool
Returns true if Discord allows reconnecting after receiving this close code.
Unknown codes are assumed to allow reconnecting, matching the documented behaviour of unexpected disconnects.
discord.js counterpart: none (@discordjs/ws decides inside the shard).
§Examples
use djs_model::gateway::CloseCode;
assert!(CloseCode::SessionTimedOut.can_reconnect());
assert!(!CloseCode::AuthenticationFailed.can_reconnect());