Skip to main content
Go to Latest
interface GatewayManager
Re-export
import { type GatewayManager } from "https://deno.land/x/discordeno@13.0.0-rc45/template/beginner/deps.ts";

Properties

secretKey: string

The secret key authorization header the bot will expect when sending payloads.

url: string

The url that all discord payloads for the dispatch type should be sent to.

reshard: boolean

Whether or not to automatically reshard.

reshardPercentage: number

The percentage at which resharding should occur.

spawnShardDelay: number

The delay in milliseconds to wait before spawning next shard. OPTIMAL IS ABOVE 2500. YOU DON"T WANT TO HIT THE RATE LIMIT!!!

maxShards: number

The maximum shard Id number. Useful for zero-downtime updates or resharding.

useOptimalLargeBotSharding: boolean

Whether or not the resharder should automatically switch to LARGE BOT SHARDING when you are above 100K servers.

shardsPerWorker: number

The amount of shards to load per worker.

maxWorkers: number

The maximum amount of workers to use for your bot.

firstShardId: number

The first shard Id to start spawning.

lastShardId: number

The last shard Id for this worker.

token: string
compress: boolean
$os: string
$browser: string
$device: string
intents: number | (keyof GatewayIntents)[]
shard: [number, number]
optional
presence: Omit<StatusUpdate, "afk" | "since">
urlWSS: string

The WSS URL that can be used for connecting to the gateway.

shardsRecommended: number

The recommended number of shards to use when connecting.

sessionStartLimitTotal: number

The total number of session starts the current user is allowed.

sessionStartLimitRemaining: number

The remaining number of session starts the current user is allowed.

sessionStartLimitResetAfter: number

Milliseconds left until limit is reset.

maxConcurrency: number

The number of identify requests allowed per 5 seconds. So, if you had a max concurrency of 16, and 16 shards for example, you could start them all up at the same time. Whereas if you had 32 shards, if you tried to start up shard 0 and 16 at the same time for example, it would not work. You can start shards 0-15 concurrently, then 16-31...

shards: Collection<number, DiscordenoShard>
loadingShards: Collection<number, { shardId: number; resolve: (value: unknown) => void; }>
buckets: Collection<number, { workers: number[][]; createNextShard: (() => Promise<unknown>)[]; }>

Stored as bucketId: { workers: [workerId, [ShardIds]], createNextShard: boolean }

utf8decoder: TextDecoder
queueResetInterval: number

The amount of milliseconds the gateway rate limit will reset in. By default 60000 or 1 minute.

maxRequestsPerInterval: number

The maximum amount of requests that the gateway can make before being rate limited. By default 120.

cache: { guildIds: Set<bigint>; loadingGuildIds: Set<bigint>; editedMessages: Collection<bigint, string>; }
prepareBuckets: prepareBuckets

Prepares the buckets for identifying

spawnShards: spawnShards

The handler for spawning ALL the shards.

createShard: createShard

Create the websocket and adds the proper handlers to the websocket.

identify: identify

Begins identification of the shard to discord.

heartbeat: heartbeat

Begins heartbeating of the shard to keep it alive.

handleDiscordPayload: (
gateway: GatewayManager,
shardId: number,
) => any

Sends the discord payload to another server.

tellWorkerToIdentify: tellWorkerToIdentify

Tell the worker to begin identifying this shard

debug: (text: GatewayDebugEvents, ...args: any[]) => unknown

Handle the different logs. Used for debugging.

resharding: { resharder: resharder; isPending: resharderIsPending; closeOldShards: resharderCloseOldShards; check: startReshardingChecks; markNewGuildShardId: markNewGuildShardId; editGuildShardIds: reshardingEditGuildShardIds; }

The methods related to resharding.

handleOnMessage: handleOnMessage

Handles the message events from websocket.

processGatewayQueue: processGatewayQueue

Handles processing queue of requests send to this shard.

closeWS: closeWS

Closes shard WebSocket connection properly.

stopGateway: stopGateway

Use this function to stop the gateway properly.

sendShardMessage: sendShardMessage

Properly adds a message to the shards queue.

resume: resume

Properly resume an old shards session.

safeRequestsPerShard: safeRequestsPerShard

Calculates the number of requests in a shard that are safe to be used.

calculateMaxShards: calculateMaxShards

Calculates the number of shards to use based on the max concurrency