GatewayManager
Documentation / @discordeno/bot / GatewayManager
Interface: GatewayManager
Defined in: packages/gateway/dist/types/manager.d.ts:138
Extends
Required
<CreateGatewayManagerOptions
>
Properties
buckets
buckets:
Map
<number
, {identifyRequests
: (value
) =>void
[];workers
:object
[]; }>
Defined in: packages/gateway/dist/types/manager.d.ts:140
The max concurrency buckets. Those will be created when the spawnShards
(which calls prepareBuckets
under the hood) function gets called.
cache
cache:
object
Defined in: packages/gateway/dist/types/manager.d.ts:287
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
calculateShardId()
calculateShardId: (
guildId
,totalShards
?) =>number
Defined in: packages/gateway/dist/types/manager.d.ts:197
Calculates the number of shards based on the guild id and total shards.
Parameters
guildId
totalShards?
number
Returns
number
calculateTotalShards()
calculateTotalShards: () =>
number
Defined in: packages/gateway/dist/types/manager.d.ts:178
Determine max number of shards to use based upon the max concurrency.
Returns
number
calculateWorkerId()
calculateWorkerId: (
shardId
) =>number
Defined in: packages/gateway/dist/types/manager.d.ts:180
Determine the id of the worker which is handling a shard.
Parameters
shardId
number
Returns
number
compress
compress:
boolean
Defined in: packages/gateway/dist/types/manager.d.ts:48
Whether incoming payloads are compressed using zlib.
Default
false
Inherited from
Required.compress
connection
connection:
object
Defined in: packages/gateway/dist/types/manager.d.ts:43
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
editBotStatus()
editBotStatus: (
data
) =>Promise
<void
>
Defined in: packages/gateway/dist/types/manager.d.ts:220
Edits the bot status in all shards that this gateway manages.
Parameters
data
The status data to set the bots status to.
Returns
Promise
<void
>
nothing
editShardStatus()
editShardStatus: (
shardId
,data
) =>Promise
<void
>
Defined in: packages/gateway/dist/types/manager.d.ts:228
Edits the bot's status on one shard.
Parameters
shardId
number
The shard id to edit the status for.
data
The status data to set the bots status to.
Returns
Promise
<void
>
nothing
events
events:
ShardEvents
Defined in: packages/gateway/dist/types/manager.d.ts:87
The events handlers
Inherited from
Required.events
firstShardId
firstShardId:
number
Defined in: packages/gateway/dist/types/manager.d.ts:11
Id of the first Shard which should get controlled by this manager.
Default
0
Inherited from
Required.firstShardId
identify()
identify: (
shardId
) =>Promise
<void
>
Defined in: packages/gateway/dist/types/manager.d.ts:191
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
>
intents
intents:
number
Defined in: packages/gateway/dist/types/manager.d.ts:55
The calculated intent value of the events which the shard should receive.
Default
0
Inherited from
Required.intents
joinVoiceChannel()
joinVoiceChannel: (
guildId
,channelId
,options
?) =>Promise
<void
>
Defined in: packages/gateway/dist/types/manager.d.ts:213
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
The ID of the guild the voice channel to leave is in.
channelId
The ID of the channel you want to join.
options?
AtLeastOne
<Omit
<UpdateVoiceState
, "channelId"
| "guildId"
>>
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
kill()
kill: (
shardId
) =>Promise
<void
>
Defined in: packages/gateway/dist/types/manager.d.ts:193
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
>
lastShardId
lastShardId:
number
Defined in: packages/gateway/dist/types/manager.d.ts:16
Id of the last Shard which should get controlled by this manager.
Default
0
Inherited from
Required.lastShardId
leaveVoiceChannel()
leaveVoiceChannel: (
guildId
) =>Promise
<void
>
Defined in: packages/gateway/dist/types/manager.d.ts:265
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
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
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: packages/gateway/dist/types/manager.d.ts:151
The logger for the gateway manager.
Overrides
Required.logger
makePresence()
makePresence: () =>
Promise
<undefined
|BotStatusUpdate
>
Defined in: packages/gateway/dist/types/manager.d.ts:109
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
preferSnakeCase
preferSnakeCase:
boolean
Defined in: packages/gateway/dist/types/manager.d.ts:26
Whether to send the discord packets in snake case form.
Default
false
Inherited from
Required.preferSnakeCase
prepareBuckets()
prepareBuckets: () =>
void
Defined in: packages/gateway/dist/types/manager.d.ts:182
Prepares all the buckets that are available for identifying the shards.
Returns
void
properties
properties:
object
Defined in: packages/gateway/dist/types/manager.d.ts:57
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
requestIdentify()
requestIdentify: (
shardId
) =>Promise
<void
>
Defined in: packages/gateway/dist/types/manager.d.ts:195
This function makes sure that the bucket is allowed to make the next identify request.
Parameters
shardId
number
Returns
Promise
<void
>
requestMembers()
requestMembers: (
guildId
,options
?) =>Promise
<object
[]>
Defined in: packages/gateway/dist/types/manager.d.ts:252
Fetches the list of members for a guild over the gateway. If gateway.cache.requestMembers.enabled
is not set, this function will return an empty array and you'll have to handle the GUILD_MEMBERS_CHUNK
events yourself.
Parameters
guildId
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
requestSoundboardSounds()
requestSoundboardSounds: (
guildIds
) =>Promise
<void
>
Defined in: packages/gateway/dist/types/manager.d.ts:285
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
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
resharding
resharding:
object
&object
Defined in: packages/gateway/dist/types/manager.d.ts:153
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
<{sessionStartLimit
: {maxConcurrency
:number
;remaining
:number
;resetAfter
:number
;total
:number
; };shards
:number
;url
:string
; }>
Handler to get shard count and other session info.
Returns
Promise
<{ sessionStartLimit
: { maxConcurrency
: number
; remaining
: number
; resetAfter
: number
; total
: number
; }; shards
: number
; 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
<{info
: {sessionStartLimit
: {maxConcurrency
:number
;remaining
:number
;resetAfter
:number
;total
:number
; };shards
:number
;url
:string
; };needed
:boolean
; }>
Handler to check if resharding is necessary.
Returns
Promise
<{ info
: { sessionStartLimit
: { maxConcurrency
: number
; remaining
: number
; resetAfter
: number
; total
: number
; }; shards
: number
; url
: string
; }; 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
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
sendPayload()
sendPayload: (
shardId
,payload
) =>Promise
<void
>
Defined in: packages/gateway/dist/types/manager.d.ts:187
Parameters
shardId
number
payload
Returns
Promise
<void
>
shards
shards:
Map
<number
,DiscordenoShard
>
Defined in: packages/gateway/dist/types/manager.d.ts:149
The shards that are created.
shardsPerWorker
shardsPerWorker:
number
Defined in: packages/gateway/dist/types/manager.d.ts:36
The amount of shards to load per worker.
Default
25
Inherited from
Required.shardsPerWorker
shutdown()
shutdown: (
code
,reason
,clearReshardingInterval
?) =>Promise
<void
>
Defined in: packages/gateway/dist/types/manager.d.ts:186
Shutdown all shards.
Parameters
code
number
reason
string
clearReshardingInterval?
boolean
Returns
Promise
<void
>
spawnShardDelay
spawnShardDelay:
number
Defined in: packages/gateway/dist/types/manager.d.ts:21
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
spawnShards()
spawnShards: () =>
Promise
<void
>
Defined in: packages/gateway/dist/types/manager.d.ts:184
Start identifying all the shards.
Returns
Promise
<void
>
tellWorkerToIdentify()
tellWorkerToIdentify: (
workerId
,shardId
,bucketId
) =>Promise
<void
>
Defined in: packages/gateway/dist/types/manager.d.ts:189
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
>
token
token:
string
Defined in: packages/gateway/dist/types/manager.d.ts:75
Bot token which is used to connect to Discord
Inherited from
Required.token
totalShards
totalShards:
number
Defined in: packages/gateway/dist/types/manager.d.ts:31
Total amount of shards your bot uses. Useful for zero-downtime updates or resharding.
Default
1
Inherited from
Required.totalShards
totalWorkers
totalWorkers:
number
Defined in: packages/gateway/dist/types/manager.d.ts:41
The total amount of workers to use for your bot.
Default
4
Inherited from
Required.totalWorkers
transportCompression
transportCompression:
null
|TransportCompression
Defined in: packages/gateway/dist/types/manager.d.ts:50
What transport compression should be used
Inherited from
Required.transportCompression
url
url:
string
Defined in: packages/gateway/dist/types/manager.d.ts:80
The URL of the gateway which should be connected to.
Default
"wss://gateway.discord.gg"
Inherited from
Required.url
version
version:
number
Defined in: packages/gateway/dist/types/manager.d.ts:85
The gateway version which should be used.
Default
10
Inherited from
Required.version