Skip to main content

DiscordenoShard

@discordeno/gatewayDocs


Documentation / @discordeno/gateway / DiscordenoShard

Class: DiscordenoShard

Constructors

new DiscordenoShard()

new DiscordenoShard(options): DiscordenoShard

Parameters

options: ShardCreateOptions

Returns

DiscordenoShard

Defined in

gateway/src/Shard.ts:70

Properties

bucket

bucket: LeakyBucket

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

Defined in

gateway/src/Shard.ts:56


connection

connection: ShardGatewayConfig

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

Defined in

gateway/src/Shard.ts:32


decompressionPromisesQueue

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

Queue for compressed payloads for Zstd Decompress

Defined in

gateway/src/Shard.ts:68


events

events: ShardEvents = {}

The shard related event handlers.

Defined in

gateway/src/Shard.ts:50


heart

heart: ShardHeart

This contains all the heartbeat information

Defined in

gateway/src/Shard.ts:34


id

id: number

The id of the shard

Defined in

gateway/src/Shard.ts:30


inflate?

optional inflate: Inflate

ZLib Inflate instance for ZLib-stream transport payloads

Defined in

gateway/src/Shard.ts:62


inflateBuffer

inflateBuffer: null | Uint8Array = null

ZLib inflate buffer

Defined in

gateway/src/Shard.ts:64


logger

logger: Pick<object, "debug" | "info" | "warn" | "error" | "fatal">

Logger for the bucket

Type declaration

debug()

debug: (...args) => void

Parameters

• ...args: any[]

Returns

void

error()

error: (...args) => void

Parameters

• ...args: any[]

Returns

void

fatal()

fatal: (...args) => void

Parameters

• ...args: any[]

Returns

void

info()

info: (...args) => void

Parameters

• ...args: any[]

Returns

void

log()

log: (level, ...args) => void

Parameters

level: LogLevels

• ...args: any[]

Returns

void

setDepth()

setDepth: (level) => void

Parameters

level: LogDepth

Returns

void

setLevel()

setLevel: (level) => void

Parameters

level: LogLevels

Returns

void

warn()

warn: (...args) => void

Parameters

• ...args: any[]

Returns

void

Defined in

gateway/src/Shard.ts:58


maxRequestsPerRateLimitTick

maxRequestsPerRateLimitTick: number = 120

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

Defined in

gateway/src/Shard.ts:36


offlineSendQueue

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

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

Defined in

gateway/src/Shard.ts:52


previousSequenceNumber

previousSequenceNumber: null | number = null

The previous payload sequence number.

Defined in

gateway/src/Shard.ts:38


rateLimitResetInterval

rateLimitResetInterval: number = 60000

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

Defined in

gateway/src/Shard.ts:40


resolves

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

Resolve internal waiting states. Mapped by SelectedEvents => ResolveFunction

Defined in

gateway/src/Shard.ts:54


resumeGatewayUrl

resumeGatewayUrl: string = ''

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

Defined in

gateway/src/Shard.ts:48


sessionId?

optional sessionId: string

Current session id of the shard if present.

Defined in

gateway/src/Shard.ts:42


socket?

optional socket: WebSocket

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

Defined in

gateway/src/Shard.ts:44


state

state: ShardState = ShardState.Offline

Current internal state of the this.

Defined in

gateway/src/Shard.ts:46


textDecoder

textDecoder: TextDecoder

Text decoder used for compressed payloads

Defined in

gateway/src/Shard.ts:60


zstdDecompress?

optional zstdDecompress: Decompress

ZStd Decompress instance for ZStd-stream transport payloads

Defined in

gateway/src/Shard.ts:66

Accessors

connectionUrl

Get Signature

get connectionUrl(): string

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

Defined in

gateway/src/Shard.ts:99


gatewayConfig

Get Signature

get gatewayConfig(): ShardGatewayConfig

The gateway configuration which is used to connect to Discord.

Returns

ShardGatewayConfig

Defined in

gateway/src/Shard.ts:94

Methods

calculateSafeRequests()

calculateSafeRequests(): number

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

Defined in

gateway/src/Shard.ts:105


checkOffline()

checkOffline(highPriority): Promise<void>

Parameters

highPriority: boolean

Returns

Promise<void>

Defined in

gateway/src/Shard.ts:112


close()

close(code, reason): void

Close the socket connection to discord if present.

Parameters

code: number

reason: string

Returns

void

Defined in

gateway/src/Shard.ts:123


connect()

connect(): Promise<DiscordenoShard>

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

Returns

Promise<DiscordenoShard>

Defined in

gateway/src/Shard.ts:130


forwardToBot()

forwardToBot(packet): void

Parameters

packet: DiscordGatewayPayload

Returns

void

Defined in

gateway/src/Shard.ts:649


handleClose()

handleClose(close): Promise<void>

Handle a gateway connection close.

Parameters

close: CloseEvent

Returns

Promise<void>

Defined in

gateway/src/Shard.ts:359


handleDiscordPacket()

handleDiscordPacket(packet): Promise<void>

Handles a incoming gateway packet.

Parameters

packet: DiscordGatewayPayload

Returns

Promise<void>

Defined in

gateway/src/Shard.ts:509


handleError()

handleError(error): void

Handle a gateway connection error

Parameters

error: Event

Returns

void

Defined in

gateway/src/Shard.ts:354


handleMessage()

handleMessage(message): Promise<void>

Handle an incoming gateway message.

Parameters

message: MessageEvent<any>

Returns

Promise<void>

Defined in

gateway/src/Shard.ts:437


identify()

identify(): Promise<void>

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

Returns

Promise<void>

Defined in

gateway/src/Shard.ts:226


isOpen()

isOpen(): boolean

Check whether the connection to Discord is currently open.

Returns

boolean

Defined in

gateway/src/Shard.ts:276


makePresence()

makePresence(): Promise<undefined | BotStatusUpdate>

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>

Defined in

gateway/src/Shard.ts:660


requestIdentify()

requestIdentify(): Promise<void>

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>

Defined in

gateway/src/Shard.ts:668


resume()

resume(): Promise<void>

Attempt to resume the previous shards session with the gateway.

Returns

Promise<void>

Defined in

gateway/src/Shard.ts:281


send()

send(message, highPriority): Promise<void>

Send a message to Discord.

Parameters

message: ShardSocketRequest

highPriority: boolean = false

Whether this message should be send asap.

Returns

Promise<void>

Defined in

gateway/src/Shard.ts:334


shardIsReady()

shardIsReady(): Promise<void>

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

Returns

Promise<void>

Defined in

gateway/src/Shard.ts:671


shutdown()

shutdown(): Promise<void>

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

Returns

Promise<void>

Defined in

gateway/src/Shard.ts:348


startHeartbeating()

startHeartbeating(interval): void

Start sending heartbeat payloads to Discord in the provided interval.

Parameters

interval: number

Returns

void

Defined in

gateway/src/Shard.ts:674


stopHeartbeating()

stopHeartbeating(): void

Stop the heartbeating process with discord.

Returns

void

Defined in

gateway/src/Shard.ts:751