Skip to main content

DiscordenoShard

@discordeno/gateway


Documentation / @discordeno/gateway / DiscordenoShard

Class: DiscordenoShard

Defined in: gateway/src/Shard.ts:28

Constructors

new DiscordenoShard()

new DiscordenoShard(options): DiscordenoShard

Defined in: gateway/src/Shard.ts:77

Parameters

options

ShardCreateOptions

Returns

DiscordenoShard

Properties

bucket

bucket: LeakyBucket

Defined in: gateway/src/Shard.ts:56

Shard bucket. Only access this if you know what you are doing. Bucket for handling shard request rate limits.


connection

connection: ShardGatewayConfig

Defined in: gateway/src/Shard.ts:32

The connection config details that this shard will used to connect to discord.


decompressionPromisesQueue

decompressionPromisesQueue: (data) => void[] = []

Defined in: gateway/src/Shard.ts:68

Queue for compressed payloads for Zstd Decompress

Parameters

data

DiscordGatewayPayload

Returns

void


events

events: ShardEvents = {}

Defined in: gateway/src/Shard.ts:50

The shard related event handlers.


heart

heart: ShardHeart

Defined in: gateway/src/Shard.ts:34

This contains all the heartbeat information


id

id: number

Defined in: gateway/src/Shard.ts:30

The id of the shard.


inflate?

optional inflate: Inflate

Defined in: gateway/src/Shard.ts:62

ZLib Inflate instance for ZLib-stream transport payloads.


inflateBuffer

inflateBuffer: null | Uint8Array = null

Defined in: gateway/src/Shard.ts:64

ZLib inflate buffer.


logger

logger: Pick<{ debug: (...args) => void; error: (...args) => void; fatal: (...args) => void; info: (...args) => void; log: (level, ...args) => void; setDepth: (level) => void; setLevel: (level) => void; warn: (...args) => void; }, "debug" | "info" | "warn" | "error" | "fatal">

Defined in: gateway/src/Shard.ts:58

Logger for the bucket.


maxRequestsPerRateLimitTick

maxRequestsPerRateLimitTick: number = 120

Defined in: gateway/src/Shard.ts:36

The maximum of requests which can be send to discord per rate limit tick. Typically this value should not be changed.


offlineSendQueue

offlineSendQueue: () => void[] = []

Defined in: gateway/src/Shard.ts:52

Cache for pending gateway requests which should have been send while the gateway went offline.

Returns

void


previousSequenceNumber

previousSequenceNumber: null | number = null

Defined in: gateway/src/Shard.ts:38

The previous payload sequence number.


rateLimitResetInterval

rateLimitResetInterval: number = 60000

Defined in: gateway/src/Shard.ts:40

In which interval (in milliseconds) the gateway resets it's rate limit.


resolveAfterClose()?

optional resolveAfterClose: (close) => void

Defined in: gateway/src/Shard.ts:75

Internal

A function that will be called once the socket is closed and handleClose() has finished updating internal states.

This is for internal purposes only, and subject to breaking changes.

Parameters

close

CloseEvent

Returns

void


resolves

resolves: Map<"READY" | "RESUMED" | "INVALID_SESSION", (payload) => void>

Defined in: gateway/src/Shard.ts:54

Resolve internal waiting states. Mapped by SelectedEvents => ResolveFunction


resumeGatewayUrl

resumeGatewayUrl: string = ''

Defined in: gateway/src/Shard.ts:48

The url provided by discord to use when resuming a connection for this this.


sessionId?

optional sessionId: string

Defined in: gateway/src/Shard.ts:42

Current session id of the shard if present.


socket?

optional socket: WebSocket

Defined in: gateway/src/Shard.ts:44

This contains the WebSocket connection to Discord, if currently connected.


state

state: ShardState = ShardState.Offline

Defined in: gateway/src/Shard.ts:46

Current internal state of the this.


textDecoder

textDecoder: TextDecoder

Defined in: gateway/src/Shard.ts:60

Text decoder used for compressed payloads.


zstdDecompress?

optional zstdDecompress: Decompress

Defined in: gateway/src/Shard.ts:66

ZStd Decompress instance for ZStd-stream transport payloads.

Accessors

connectionUrl

Get Signature

get connectionUrl(): string

Defined in: gateway/src/Shard.ts:106

The url to connect to. Initially this is the discord gateway url, and then is switched to resume gateway url once a READY is received.

Returns

string


gatewayConfig

Get Signature

get gatewayConfig(): ShardGatewayConfig

Defined in: gateway/src/Shard.ts:101

The gateway configuration which is used to connect to Discord.

Returns

ShardGatewayConfig

Methods

calculateSafeRequests()

calculateSafeRequests(): number

Defined in: gateway/src/Shard.ts:112

Calculate the amount of requests which can safely be made per rate limit interval, before the gateway gets disconnected due to an exceeded rate limit.

Returns

number


checkOffline()

checkOffline(highPriority): Promise<void>

Defined in: gateway/src/Shard.ts:119

Parameters

highPriority

boolean

Returns

Promise<void>


close()

close(code, reason): Promise<void>

Defined in: gateway/src/Shard.ts:130

Close the socket connection to discord if present.

Parameters

code

number

reason

string

Returns

Promise<void>


connect()

connect(): Promise<DiscordenoShard>

Defined in: gateway/src/Shard.ts:157

Connect the shard with the gateway and start heartbeating. This will not identify the shard to the gateway.

Returns

Promise<DiscordenoShard>


forwardToBot()

forwardToBot(packet): void

Defined in: gateway/src/Shard.ts:680

Parameters

packet

DiscordGatewayPayload

Returns

void


handleClose()

handleClose(close): Promise<void>

Defined in: gateway/src/Shard.ts:386

Handle a gateway connection close.

Parameters

close

CloseEvent

Returns

Promise<void>


handleDiscordPacket()

handleDiscordPacket(packet): Promise<void>

Defined in: gateway/src/Shard.ts:539

Handles a incoming gateway packet.

Parameters

packet

DiscordGatewayPayload

Returns

Promise<void>


handleError()

handleError(error): void

Defined in: gateway/src/Shard.ts:381

Handle a gateway connection error

Parameters

error

Event

Returns

void


handleMessage()

handleMessage(message): Promise<void>

Defined in: gateway/src/Shard.ts:467

Handle an incoming gateway message.

Parameters

message

MessageEvent

Returns

Promise<void>


identify()

identify(): Promise<void>

Defined in: gateway/src/Shard.ts:253

Identify the shard to the gateway. If not connected, this will also connect the shard to the gateway.

Returns

Promise<void>


isOpen()

isOpen(): boolean

Defined in: gateway/src/Shard.ts:303

Check whether the connection to Discord is currently open.

Returns

boolean


makePresence()

makePresence(): Promise<undefined | BotStatusUpdate>

Defined in: gateway/src/Shard.ts:691

Override in order to make the shards presence. async in case devs create the presence based on eg. database values. Passing the shard's id there to make it easier for the dev to use this function.

Returns

Promise<undefined | BotStatusUpdate>


requestIdentify()

requestIdentify(): Promise<void>

Defined in: gateway/src/Shard.ts:699

This function communicates with the management process, in order to know whether its free to identify. When this function resolves, this means that the shard is allowed to send an identify payload to discord.

Returns

Promise<void>


resume()

resume(): Promise<void>

Defined in: gateway/src/Shard.ts:308

Attempt to resume the previous shards session with the gateway.

Returns

Promise<void>


send()

send(message, highPriority): Promise<void>

Defined in: gateway/src/Shard.ts:361

Send a message to Discord.

Parameters

message

ShardSocketRequest

highPriority

boolean = false

Whether this message should be send asap.

Returns

Promise<void>


shardIsReady()

shardIsReady(): Promise<void>

Defined in: gateway/src/Shard.ts:702

This function communicates with the management process, in order to tell it can identify the next shard.

Returns

Promise<void>


shutdown()

shutdown(): Promise<void>

Defined in: gateway/src/Shard.ts:375

Shutdown the this. Forcefully disconnect the shard from Discord. The shard may not attempt to reconnect with Discord.

Returns

Promise<void>


startHeartbeating()

startHeartbeating(interval): void

Defined in: gateway/src/Shard.ts:705

Start sending heartbeat payloads to Discord in the provided interval.

Parameters

interval

number

Returns

void


stopHeartbeating()

stopHeartbeating(): void

Defined in: gateway/src/Shard.ts:782

Stop the heartbeating process with discord.

Returns

void