ShardManager
Defined in: packages/sharding/src/index.ts:310
Manages independent Discord Gateway shards with explicit destruction and reinitialization semantics.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ShardManager(
options):ShardManager
Defined in: packages/sharding/src/index.ts:356
Creates a shard manager.
Parameters
Section titled “Parameters”options
Section titled “options”Sharding configuration.
Returns
Section titled “Returns”ShardManager
Throws
Section titled “Throws”If token or intents are invalid.
Throws
Section titled “Throws”If shard count is invalid.
Properties
Section titled “Properties”shards
Section titled “shards”
readonlyshards:Map<number,Gateway>
Defined in: packages/sharding/src/index.ts:314
Active Gateway shards indexed by shard identifier.
IDENTIFY_INTERVAL
Section titled “IDENTIFY_INTERVAL”
readonlystaticIDENTIFY_INTERVAL:5000=5000
Defined in: packages/sharding/src/index.ts:312
Discord’s minimum interval between IDENTIFY payloads, in milliseconds.
Accessors
Section titled “Accessors”shardCount
Section titled “shardCount”Get Signature
Section titled “Get Signature”get shardCount():
number
Defined in: packages/sharding/src/index.ts:316
Total shards in the deployment once initialized, 0 before and after destroy().
Returns
Section titled “Returns”number
shardIds
Section titled “shardIds”Get Signature
Section titled “Get Signature”get shardIds():
number[]
Defined in: packages/sharding/src/index.ts:320
IDs of the shards this manager owns.
Returns
Section titled “Returns”number[]
Methods
Section titled “Methods”addShards()
Section titled “addShards()”addShards(
shardIds):Promise<void>
Defined in: packages/sharding/src/index.ts:541
Takes over more shards of the same deployment (recovery after another cluster gave up) and connects them through the same IDENTIFY path.
Parameters
Section titled “Parameters”shardIds
Section titled “shardIds”readonly number[]
Returns
Section titled “Returns”Promise<void>
Throws
Section titled “Throws”If an ID is invalid, already owned, or the manager is not initialized.
checkAutoScale()
Section titled “checkAutoScale()”checkAutoScale():
Promise<void>
Defined in: packages/sharding/src/index.ts:703
Checks if the recommended shard count has changed and reconnects if so.
Returns
Section titled “Returns”Promise<void>
connect()
Section titled “connect()”connect():
Promise<void>
Defined in: packages/sharding/src/index.ts:511
Connects all shards sequentially. A destroyed manager is reinitialized before connecting.
Returns
Section titled “Returns”Promise<void>
A promise fulfilled after all shards connect.
Throws
Section titled “Throws”If a shard fails to connect.
destroy()
Section titled “destroy()”destroy():
void
Defined in: packages/sharding/src/index.ts:723
Permanently closes the current shard set and releases Gateway resources. The next connect recreates them.
Returns
Section titled “Returns”void
Nothing.
fetchGatewayInfo()
Section titled “fetchGatewayInfo()”fetchGatewayInfo():
Promise<GatewayBotInfo>
Defined in: packages/sharding/src/index.ts:505
Retrieves /gateway/bot: recommended shards and the IDENTIFY budget. Remembered for pacing the next connect.
Returns
Section titled “Returns”Promise<GatewayBotInfo>
Throws
Section titled “Throws”If discovery fails or returns invalid data.
fetchRecommendedShardCount()
Section titled “fetchRecommendedShardCount()”fetchRecommendedShardCount():
Promise<number>
Defined in: packages/sharding/src/index.ts:497
Retrieves Discord’s recommended shard count.
Returns
Section titled “Returns”Promise<number>
Recommended shard count.
Throws
Section titled “Throws”If discovery fails or returns invalid data.
get(
id):Gateway|undefined
Defined in: packages/sharding/src/index.ts:786
Gets a shard by ID.
Parameters
Section titled “Parameters”number
Shard identifier.
Returns
Section titled “Returns”Gateway | undefined
Gateway instance or undefined.
getShardIdForGuild()
Section titled “getShardIdForGuild()”getShardIdForGuild(
guildId):number
Defined in: packages/sharding/src/index.ts:769
Calculates the target shard ID for a Discord guild snowflake.
Parameters
Section titled “Parameters”guildId
Section titled “guildId”string
Guild snowflake.
Returns
Section titled “Returns”number
Shard identifier.
health()
Section titled “health()”health():
ShardHealth[]
Defined in: packages/sharding/src/index.ts:790
Returns each shard’s connection state, lifecycle status and heartbeat latency.
Returns
Section titled “Returns”off<
E>(event,listener):this
Defined in: packages/sharding/src/index.ts:748
Stops listening for a shard event.
Type Parameters
Section titled “Type Parameters”E extends keyof ShardManagerEvents
Parameters
Section titled “Parameters”E
listener
Section titled “listener”(…args) => void
Returns
Section titled “Returns”this
This manager.
on<
E>(event,listener):this
Defined in: packages/sharding/src/index.ts:738
Listens for an aggregated shard event.
Type Parameters
Section titled “Type Parameters”E extends keyof ShardManagerEvents
Parameters
Section titled “Parameters”E
listener
Section titled “listener”(…args) => void
Returns
Section titled “Returns”this
This manager.
report()
Section titled “report()”report(
metrics?):WorkerReport
Defined in: packages/sharding/src/index.ts:808
A health report for the parent: shard health and, on request, process metrics.
Parameters
Section titled “Parameters”metrics?
Section titled “metrics?”boolean = false
Returns
Section titled “Returns”reshard()
Section titled “reshard()”reshard(
count):Promise<void>
Defined in: packages/sharding/src/index.ts:717
Forces a reshard to a new shard count, replacing all active shards.
Parameters
Section titled “Parameters”number
New shard count.
Returns
Section titled “Returns”Promise<void>
sendVoiceState()
Section titled “sendVoiceState()”sendVoiceState(
guildId,channelId,options?):boolean
Defined in: packages/sharding/src/index.ts:774
Sends a voice state update (op 4) on the shard that owns the guild.
Parameters
Section titled “Parameters”guildId
Section titled “guildId”string
channelId
Section titled “channelId”string | null
options?
Section titled “options?”selfDeaf?
Section titled “selfDeaf?”boolean
selfMute?
Section titled “selfMute?”boolean
Returns
Section titled “Returns”boolean
Whether it was sent; false if that shard is absent or disconnected.
values()
Section titled “values()”values():
ShardInfo[]
Defined in: packages/sharding/src/index.ts:847
Returns information for all managed shards.
Returns
Section titled “Returns”Shard information snapshots.