Members
(private) closeSequence :number
The sequence of the shard after close
Type:
- number
(private) connectedAt :number
Time when the WebSocket connection was opened
Type:
- number
(private, nullable) connection :WebSocket
The WebSocket connection for the current shard
Type:
- WebSocket
(private) eventsAttached :boolean
If the manager attached its event handlers on the shard
Type:
- boolean
(private, nullable) expectedGuilds :Set.<string>
A set of guild IDs this shard expects to receive
Type:
- Set.<string>
(private, nullable) helloTimeout :NodeJS.Timeout
The HELLO timeout
Type:
- NodeJS.Timeout
id :number
The ID of the shard
Type:
- number
(private, nullable) inflate :Inflate
The compression to use
Type:
- Inflate
(private) lastHeartbeatAcked :boolean
If we received a heartbeat ack back. Used to identify zombie connections
Type:
- boolean
(private) lastPingTimestamp :number
The last time a ping was sent (a timestamp)
Type:
- number
manager :WebSocketManager
The WebSocketManager of the shard
Type:
ping :number
The previous heartbeat ping of the shard
Type:
- number
(private) ratelimit :Object
Contains the rate limit queue and metadata
Type:
- Object
(private, nullable) readyTimeout :NodeJS.Timeout
The ready timeout
Type:
- NodeJS.Timeout
(private) sequence :number
The current sequence of the shard
Type:
- number
(private) sessionID :string
The current session ID of the shard
Type:
- string
status :Status
The current status of the shard
Type:
Methods
(private) _cleanupConnection()
Cleans up the WebSocket connection listeners.
(private) _emitDestroyed()
Emits the DESTROYED event on the shard
(private) _send(data) → {void}
Sends data, bypassing the queue.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | Packet to send |
Returns:
- Type
- void
(private) ackHeartbeat()
Acknowledges a heartbeat.
(private) checkReady()
Checks if the shard can be marked as ready
(private) connect() → {Promise.<void>}
Connects the shard to the gateway.
Returns:
A promise that will resolve if the shard turns ready successfully,
or reject if we couldn't connect
- Type
- Promise.<void>
(private) debug(message)
Emits a debug event.
Parameters:
Name | Type | Description |
---|---|---|
message |
string | The debug message |
(private) destroy(optionsopt)
Destroys this shard and closes its WebSocket connection.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
options |
Object |
<optional> |
{ closeCode: 1000, reset: false, emit: true, log: true } | Options for destroying the shard |
(private) identify() → {void}
Identifies the client on the connection.
Returns:
- Type
- void
(private) identifyNew()
Identifies as a new connection on the gateway.
(private) identifyResume()
Resumes a session on the gateway.
(private) onClose(event)
Called whenever a connection to the gateway is closed.
Parameters:
Name | Type | Description |
---|---|---|
event |
CloseEvent | Close event that was received |
(private) onError(event)
Called whenever an error occurs with the WebSocket.
Parameters:
Name | Type | Description |
---|---|---|
event |
ErrorEvent | The error that occurred |
(private) onMessage(event)
Called whenever a message is received.
Parameters:
Name | Type | Description |
---|---|---|
event |
MessageEvent | Event received |
(private) onOpen()
Called whenever a connection is opened to the gateway.
(private) onPacket(packet)
Called whenever a packet is received.
Parameters:
Name | Type | Description |
---|---|---|
packet |
Object | The received packet |
(private) processQueue() → {void}
Processes the current WebSocket queue.
Returns:
- Type
- void
send(data, importantopt)
Adds a packet to the queue to be sent to the gateway.
If you use this method, make sure you understand that you need to provide
a full [Payload](https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-commands).
Do not use this method if you don't know what you're doing.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
Object | The full packet to send | ||
important |
boolean |
<optional> |
false | If this packet should be added first in queue |
(private) sendHeartbeat(tagopt, ignoreHeartbeatAckopt)
Sends a heartbeat to the WebSocket.
If this shard didn't receive a heartbeat last time, it will destroy it and reconnect
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
tag |
string |
<optional> |
'HeartbeatTimer' | What caused this heartbeat to be sent |
ignoreHeartbeatAck |
boolean |
<optional> |
If we should send the heartbeat forcefully. |
(private) setHeartbeatTimer(time)
Sets the heartbeat timer for this shard.
Parameters:
Name | Type | Description |
---|---|---|
time |
number | If -1, clears the interval, any other number sets an interval |
(private) setHelloTimeout(timeopt)
Sets the HELLO packet timeout.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
time |
number |
<optional> |
If set to -1, it will clear the hello timeout timeout |
Events
allReady
Emitted when the shard is fully ready.
This event is emitted if:
* all guilds were received by this shard
* the ready timeout expired, and some guilds are unavailable
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
unavailableGuilds |
Set.<string> |
<nullable> |
Set of unavailable guilds, if any |
close
Emitted when a shard's WebSocket closes.
Parameters:
Name | Type | Description |
---|---|---|
event |
CloseEvent | The received event |
destroyed
Emitted when a shard is destroyed, but no WebSocket connection was present.
ready
Emitted when the shard receives the READY payload and is now waiting for guilds
resumed
Emitted when the shard resumes successfully