Skip to main content

DiscordenoShard

Documentation


Documentation / @discordeno/gateway / DiscordenoShard

Class: DiscordenoShard

Defined in: Shard.ts:18

Constructors​

Constructor​

new DiscordenoShard(options): DiscordenoShard

Defined in: Shard.ts:73

Parameters​

options​

ShardCreateOptions

Returns​

DiscordenoShard

Properties​

bucket​

bucket: LeakyBucket

Defined in: Shard.ts:46

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


connection​

connection: ShardGatewayConfig

Defined in: Shard.ts:22

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


events​

events: ShardEvents = {}

Defined in: Shard.ts:40

The shard related event handlers.


heart​

heart: ShardHeart

Defined in: Shard.ts:24

This contains all the heartbeat information


id​

id: number

Defined in: Shard.ts:20

The id of the shard.


inflate?​

optional inflate?: Inflate | ZstdDecompress

Defined in: Shard.ts:62

zlib Inflate or zstd decompress instance for transport payloads.


inflateBuffer​

inflateBuffer: Uint8Array<ArrayBufferLike> | null = null

Defined in: Shard.ts:64

zlib inflate/zstd buffer.


logger​

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

Defined in: Shard.ts:48

Logger for the bucket.


maxRequestsPerRateLimitTick​

maxRequestsPerRateLimitTick: number = 120

Defined in: Shard.ts:26

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: Shard.ts:42

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

Returns​

void


previousSequenceNumber​

previousSequenceNumber: number | null = null

Defined in: Shard.ts:28

The previous payload sequence number.


rateLimitResetInterval​

rateLimitResetInterval: number = 60000

Defined in: Shard.ts:30

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


resolves​

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

Defined in: Shard.ts:44

Resolve internal waiting states. Mapped by SelectedEvents => ResolveFunction


resumeGatewayUrl​

resumeGatewayUrl: string = ''

Defined in: Shard.ts:38

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


sessionId?​

optional sessionId?: string

Defined in: Shard.ts:32

Current session id of the shard if present.


socket?​

optional socket?: WebSocket

Defined in: Shard.ts:34

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


state​

state: ShardState = ShardState.Offline

Defined in: Shard.ts:36

Current internal state of the this.


textDecoder​

textDecoder: TextDecoder

Defined in: Shard.ts:60

Text decoder used for compressed payloads.

Accessors​

connectionUrl​

Get Signature​

get connectionUrl(): string

Defined in: Shard.ts:101

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: Shard.ts:96

The gateway configuration which is used to connect to Discord.

Returns​

ShardGatewayConfig

Methods​

calculateSafeRequests()​

calculateSafeRequests(): number

Defined in: Shard.ts:107

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: Shard.ts:114

Parameters​

highPriority​

boolean

Returns​

Promise<void>


close()​

close(code, reason): Promise<void>

Defined in: Shard.ts:125

Close the socket connection to discord if present.

Parameters​

code​

number

reason​

string

Returns​

Promise<void>


connect()​

connect(): Promise<DiscordenoShard>

Defined in: Shard.ts:154

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

Returns​

Promise<DiscordenoShard>


handleClose()​

handleClose(close): Promise<void>

Defined in: Shard.ts:378

Handle a gateway connection close.

Parameters​

close​

CloseEvent

Returns​

Promise<void>


handleDiscordPacket()​

handleDiscordPacket(packet): Promise<void>

Defined in: Shard.ts:527

Handles a incoming gateway packet.

Parameters​

packet​

DiscordGatewayPayload

Returns​

Promise<void>


handleError()​

handleError(error): void

Defined in: Shard.ts:373

Handle a gateway connection error

Parameters​

error​

Event

Returns​

void


handleMessage()​

handleMessage(message): Promise<void>

Defined in: Shard.ts:470

Handle an incoming gateway message.

Parameters​

message​

MessageEvent

Returns​

Promise<void>


identify()​

identify(bypassRequest?): Promise<void>

Defined in: Shard.ts:242

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

Parameters​

bypassRequest?​

boolean = false

Whether to bypass the requestIdentify handler and identify immediately. This should be used carefully as it can cause invalid sessions.

Returns​

Promise<void>


isOpen()​

isOpen(): boolean

Defined in: Shard.ts:295

Check whether the connection to Discord is currently open.

Returns​

boolean


makePresence()​

makePresence(): Promise<DiscordUpdatePresence | undefined>

Defined in: Shard.ts:674

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<DiscordUpdatePresence | undefined>


requestIdentify()​

requestIdentify(): Promise<void>

Defined in: Shard.ts:682

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: Shard.ts:300

Attempt to resume the previous shards session with the gateway.

Returns​

Promise<void>


send()​

send(message, highPriority?): Promise<void>

Defined in: Shard.ts:353

Send a message to Discord.

Parameters​

message​

ShardSocketRequest

highPriority?​

boolean = false

Whether this message should be send asap.

Returns​

Promise<void>


shutdown()​

shutdown(): Promise<void>

Defined in: Shard.ts:367

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: Shard.ts:685

Start sending heartbeat payloads to Discord in the provided interval.

Parameters​

interval​

number

Returns​

void


stopHeartbeating()​

stopHeartbeating(): void

Defined in: Shard.ts:760

Stop the heartbeating process with discord.

Returns​

void