Skip to main content

GatewayManager

@discordeno/gatewayDocs


Documentation / @discordeno/gateway / GatewayManager

Interface: GatewayManager

Extends

Properties

buckets

buckets: Map<number, object>

The max concurrency buckets. Those will be created when the spawnShards (which calls prepareBuckets under the hood) function gets called.

Defined in

gateway/src/manager.ts:728


cache

cache: object

This managers cache related settings.

requestMembers

requestMembers: object

requestMembers.enabled

requestMembers.enabled: boolean

Whether or not request member requests should be cached.

Default
false

requestMembers.pending

requestMembers.pending: Collection<string, RequestMemberRequest>

The pending requests.

Overrides

Required.cache

Defined in

gateway/src/manager.ts:869


calculateShardId()

calculateShardId: (guildId, totalShards?) => number

Calculates the number of shards based on the guild id and total shards.

Parameters

guildId: BigString

totalShards?: number

Returns

number

Defined in

gateway/src/manager.ts:779


calculateTotalShards()

calculateTotalShards: () => number

Determine max number of shards to use based upon the max concurrency.

Returns

number

Defined in

gateway/src/manager.ts:760


calculateWorkerId()

calculateWorkerId: (shardId) => number

Determine the id of the worker which is handling a shard.

Parameters

shardId: number

Returns

number

Defined in

gateway/src/manager.ts:762


compress

compress: boolean

Whether incoming payloads are compressed using zlib.

Default

false

Inherited from

Required.compress

Defined in

gateway/src/manager.ts:635


connection

connection: object

Important data which is used by the manager to connect shards to the gateway.

sessionStartLimit

sessionStartLimit: object

sessionStartLimit.maxConcurrency

sessionStartLimit.maxConcurrency: number

sessionStartLimit.remaining

sessionStartLimit.remaining: number

sessionStartLimit.resetAfter

sessionStartLimit.resetAfter: number

sessionStartLimit.total

sessionStartLimit.total: number

shards

shards: number

url

url: string

Inherited from

Required.connection

Defined in

gateway/src/manager.ts:630


editBotStatus()

editBotStatus: (data) => Promise<void>

Edits the bot status in all shards that this gateway manages.

Parameters

data: StatusUpdate

The status data to set the bots status to.

Returns

Promise<void>

nothing

Defined in

gateway/src/manager.ts:802


editShardStatus()

editShardStatus: (shardId, data) => Promise<void>

Edits the bot's status on one shard.

Parameters

shardId: number

The shard id to edit the status for.

data: StatusUpdate

The status data to set the bots status to.

Returns

Promise<void>

nothing

Defined in

gateway/src/manager.ts:810


events

events: ShardEvents

The events handlers

Inherited from

Required.events

Defined in

gateway/src/manager.ts:674


firstShardId

firstShardId: number

Id of the first Shard which should get controlled by this manager.

Default

0

Inherited from

Required.firstShardId

Defined in

gateway/src/manager.ts:598


identify()

identify: (shardId) => Promise<void>

Tell the manager to identify a Shard. If this Shard is not already managed this will also add the Shard to the manager.

Parameters

shardId: number

Returns

Promise<void>

Defined in

gateway/src/manager.ts:773


intents

intents: number

The calculated intent value of the events which the shard should receive.

Default

0

Inherited from

Required.intents

Defined in

gateway/src/manager.ts:642


joinVoiceChannel()

joinVoiceChannel: (guildId, channelId, options?) => Promise<void>

Connects the bot user to a voice or stage channel.

This function sends the Update Voice State gateway command over the gateway behind the scenes.

Parameters

guildId: BigString

The ID of the guild the voice channel to leave is in.

channelId: BigString

The ID of the channel you want to join.

options?: AtLeastOne<Omit<UpdateVoiceState, "guildId" | "channelId">>

Returns

Promise<void>

Remarks

Requires the CONNECT permission.

Fires a Voice State Update gateway event.

See

https://discord.com/developers/docs/topics/gateway#update-voice-state

Defined in

gateway/src/manager.ts:795


kill()

kill: (shardId) => Promise<void>

Kill a shard. Close a shards connection to Discord's gateway (if any) and remove it from the manager.

Parameters

shardId: number

Returns

Promise<void>

Defined in

gateway/src/manager.ts:775


lastShardId

lastShardId: number

Id of the last Shard which should get controlled by this manager.

Default

0

Inherited from

Required.lastShardId

Defined in

gateway/src/manager.ts:603


leaveVoiceChannel()

leaveVoiceChannel: (guildId) => Promise<void>

Leaves the voice channel the bot user is currently in.

This function sends the Update Voice State gateway command over the gateway behind the scenes.

Parameters

guildId: BigString

The ID of the guild the voice channel to leave is in.

Returns

Promise<void>

Remarks

Fires a Voice State Update gateway event.

See

https://discord.com/developers/docs/topics/gateway#update-voice-state

Defined in

gateway/src/manager.ts:847


logger

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

The logger for the gateway manager.

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

Overrides

Required.logger

Defined in

gateway/src/manager.ts:739


makePresence()

makePresence: () => Promise<undefined | BotStatusUpdate>

Make the presence for when the bot connects to the gateway

Returns

Promise<undefined | BotStatusUpdate>

Remarks

This function will be called each time a Shard is going to identify

Inherited from

Required.makePresence

Defined in

gateway/src/manager.ts:696


preferSnakeCase

preferSnakeCase: boolean

Whether to send the discord packets in snake case form.

Default

false

Inherited from

Required.preferSnakeCase

Defined in

gateway/src/manager.ts:613


prepareBuckets()

prepareBuckets: () => void

Prepares all the buckets that are available for identifying the shards.

Returns

void

Defined in

gateway/src/manager.ts:764


properties

properties: object

Identify properties to use

browser

browser: string

The "browser" where this shard is running on.

Default
"Discordeno"

device

device: string

The device on which the shard is running.

Default
"Discordeno"

os

os: string

Operating system the shard runs on.

Default
"darwin" | "linux" | "windows"

Inherited from

Required.properties

Defined in

gateway/src/manager.ts:644


requestIdentify()

requestIdentify: (shardId) => Promise<void>

This function makes sure that the bucket is allowed to make the next identify request.

Parameters

shardId: number

Returns

Promise<void>

Defined in

gateway/src/manager.ts:777


requestMembers()

requestMembers: (guildId, options?) => Promise<object[]>

Fetches the list of members for a guild over the gateway.

Parameters

guildId: BigString

The ID of the guild to get the list of members for.

options?: Omit<RequestGuildMembers, "guildId">

The parameters for the fetching of the members.

Returns

Promise<object[]>

Remarks

If requesting the entire member list:

  • Requires the GUILD_MEMBERS intent.

If requesting presences (presences set to true):

  • Requires the GUILD_PRESENCES intent.

If requesting a prefix (query non-undefined):

  • Returns a maximum of 100 members.

If requesting a users by ID (userIds non-undefined):

  • Returns a maximum of 100 members.

Fires a Guild Members Chunk gateway event for every 1000 members fetched.

See

https://discord.com/developers/docs/topics/gateway#request-guild-members

Defined in

gateway/src/manager.ts:834


requestSoundboardSounds()

requestSoundboardSounds: (guildIds) => Promise<void>

Used to request soundboard sounds for a list of guilds.

This function sends multiple (see remarks) Request Soundboard Sounds gateway command over the gateway behind the scenes.

Parameters

guildIds: BigString[]

The guilds to get the sounds from

Returns

Promise<void>

Remarks

Fires a Soundboard Sounds gateway event.

⚠️ Discord will send the Soundboard Sounds for each of the guild ids however you may not receive the same number of events as the ids passed to Request Soundboard Sounds for one of the following reasons:

  • The bot is not in the server provided
  • The shard the message has been sent from does not receive events for the specified guild

To avoid this Discordeno will automatically try to group the ids based on what shard they will need to be sent, but this involves sending multiple messages in multiple shards

See

https://discord.com/developers/docs/topics/gateway-events#request-soundboard-sounds

Defined in

gateway/src/manager.ts:867


resharding

resharding: object & object

Everything related to resharding.

Type declaration

checkInterval

checkInterval: number

The interval in milliseconds, of how often to check whether resharding is needed and reshard automatically. Set to -1 to disable auto resharding.

Default
28800000 (8 hours)
enabled

enabled: boolean

Whether or not automated resharding should be enabled.

Default
true
getSessionInfo()?

optional getSessionInfo: () => Promise<object>

Handler to get shard count and other session info.

Returns

Promise<object>

sessionStartLimit

sessionStartLimit: object

sessionStartLimit.maxConcurrency

sessionStartLimit.maxConcurrency: number

sessionStartLimit.remaining

sessionStartLimit.remaining: number

sessionStartLimit.resetAfter

sessionStartLimit.resetAfter: number

sessionStartLimit.total

sessionStartLimit.total: number

shards

shards: number

url

url: string

shardsFullPercentage

shardsFullPercentage: number

The % of how full a shard is when resharding should be triggered.

Remarks

We use discord recommended shard value to get an approximation of the shard full percentage to compare with this value so the bot may not reshard at the exact percentage provided but may reshard when it is a bit higher than the provided percentage. For accurate calculation, you may override the checkIfReshardingIsNeeded function

Default
80 as in 80%
updateGuildsShardId()?

optional updateGuildsShardId: (guildIds, shardId) => Promise<void>

Handler to edit the shard id on any cached guilds.

Parameters

guildIds: string[]

shardId: number

Returns

Promise<void>

Type declaration

checkIfReshardingIsNeeded()

checkIfReshardingIsNeeded: () => Promise<object>

Handler to check if resharding is necessary.

Returns

Promise<object>

info?

optional info: object

info.sessionStartLimit

info.sessionStartLimit: object

info.sessionStartLimit.maxConcurrency

info.sessionStartLimit.maxConcurrency: number

info.sessionStartLimit.remaining

info.sessionStartLimit.remaining: number

info.sessionStartLimit.resetAfter

info.sessionStartLimit.resetAfter: number

info.sessionStartLimit.total

info.sessionStartLimit.total: number

info.shards

info.shards: number

info.url

info.url: string

needed

needed: boolean

checkIntervalId?

optional checkIntervalId: Timeout

The interval id of the check interval. This is used to clear the interval when the manager is shutdown.

pendingShards

pendingShards: Collection<number, DiscordenoShard>

Holds the pending shards that have been created and are pending all shards finish loading.

reshard()

reshard: (info) => Promise<void>

Handler to begin resharding.

Parameters

info: object & object

Returns

Promise<void>

shardIsPending()

shardIsPending: (shard) => Promise<void>

Handler to alert the gateway that a shard(resharded) is online. It should now wait for all shards to be pending before shutting off old shards.

Parameters

shard: DiscordenoShard

Returns

Promise<void>

shards

shards: Collection<number, DiscordenoShard>

Holds the shards that resharding has created. Once resharding is done, this replaces the gateway.shards

tellWorkerToPrepare()

tellWorkerToPrepare: (workerId, shardId, bucketId) => Promise<void>

Handler to communicate to a worker that a shard needs to be created.

Parameters

workerId: number

shardId: number

bucketId: number

Returns

Promise<void>

Overrides

Required.resharding

Defined in

gateway/src/manager.ts:741


sendPayload()

sendPayload: (shardId, payload) => Promise<void>

Parameters

shardId: number

payload: ShardSocketRequest

Returns

Promise<void>

Defined in

gateway/src/manager.ts:769


shards

shards: Map<number, DiscordenoShard>

The shards that are created.

Defined in

gateway/src/manager.ts:737


shardsPerWorker

shardsPerWorker: number

The amount of shards to load per worker.

Default

25

Inherited from

Required.shardsPerWorker

Defined in

gateway/src/manager.ts:623


shutdown()

shutdown: (code, reason, clearReshardingInterval?) => Promise<void>

Shutdown all shards.

Parameters

code: number

reason: string

clearReshardingInterval?: boolean

Returns

Promise<void>

Defined in

gateway/src/manager.ts:768


spawnShardDelay

spawnShardDelay: number

Delay in milliseconds to wait before spawning next shard. OPTIMAL IS ABOVE 5100. YOU DON'T WANT TO HIT THE RATE LIMIT!!!

Default

5300

Inherited from

Required.spawnShardDelay

Defined in

gateway/src/manager.ts:608


spawnShards()

spawnShards: () => Promise<void>

Start identifying all the shards.

Returns

Promise<void>

Defined in

gateway/src/manager.ts:766


tellWorkerToIdentify()

tellWorkerToIdentify: (workerId, shardId, bucketId) => Promise<void>

Allows users to hook in and change to communicate to different workers across different servers or anything they like. For example using redis pubsub to talk to other servers.

Parameters

workerId: number

shardId: number

bucketId: number

Returns

Promise<void>

Defined in

gateway/src/manager.ts:771


token

token: string

Bot token which is used to connect to Discord

Inherited from

Required.token

Defined in

gateway/src/manager.ts:662


totalShards

totalShards: number

Total amount of shards your bot uses. Useful for zero-downtime updates or resharding.

Default

1

Inherited from

Required.totalShards

Defined in

gateway/src/manager.ts:618


totalWorkers

totalWorkers: number

The total amount of workers to use for your bot.

Default

4

Inherited from

Required.totalWorkers

Defined in

gateway/src/manager.ts:628


transportCompression

transportCompression: null | TransportCompression

What transport compression should be used

Inherited from

Required.transportCompression

Defined in

gateway/src/manager.ts:637


url

url: string

The URL of the gateway which should be connected to.

Default

"wss://gateway.discord.gg"

Inherited from

Required.url

Defined in

gateway/src/manager.ts:667


version

version: number

The gateway version which should be used.

Default

10

Inherited from

Required.version

Defined in

gateway/src/manager.ts:672