ShardClientUtil
classe · deprecated · Source
Helper class for sharded clients spawned as a child process/worker, such as from a ShardingManager. Utilizes IPC to send and receive data to/from the master process and other shards.
Properties
client
Client for the shard Source
mode
Mode the shard was spawned with Source
parentPort
Message port for the master process (only when ShardClientUtil#mode is worker) Source
ids
Array of shard ids of this client Source
count
Total number of shards Source
Methods
send
Sends a message to the master process. Parameters
| Name | Type | Description |
|---|---|---|
message | * | Message to send |
Returns: Promise<void>Source
fetchClientValues
Fetches a client property value of each shard, or a given shard. Parameters
| Name | Type | Description |
|---|---|---|
prop | string | Name of the client property to get, using periods for nesting |
shard? | number | Shard to fetch property from, all if undefined |
Returns: Promise<(*\|Array<*>)>
client.shard.fetchClientValues('guilds.cache.size')
.then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`))
.catch(console.error);broadcastEval
Evaluates a script or function on all shards, or a given shard, in the context of the Clients. Parameters
| Name | Type | Description |
|---|---|---|
script | function | JavaScript to run on each shard |
options? | BroadcastEvalOptions | The options for the broadcast Default: {}. |
Returns: Promise<(*\|Array<*>)> — Results of the script execution
client.shard.broadcastEval(client => client.guilds.cache.size)
.then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`))
.catch(console.error);respawnAll
Requests a respawn of all shards. Parameters
| Name | Type | Description |
|---|---|---|
options? | MultipleShardRespawnOptions | Options for respawning shards |
Returns: Promise<void> — Resolves upon the message being sent Source
_handleMessage
Handles an IPC message. Parameters
| Name | Type | Description |
|---|---|---|
message | * | Message received |
| Source |
_respond
Sends a message to the master process, emitting an error from the client upon failure. Parameters
| Name | Type | Description |
|---|---|---|
type | string | Type of response to send |
message | * | Message to send |
| Source |
incrementMaxListeners
Increments max listeners by one for a given emitter, if they are not zero. Parameters
| Name | Type | Description |
|---|---|---|
emitter | EventEmitter | process | The emitter that emits the events. |
| Source |
decrementMaxListeners
Decrements max listeners by one for a given emitter, if they are not zero. Parameters
| Name | Type | Description |
|---|---|---|
emitter | EventEmitter | process | The emitter that emits the events. |
| Source |
singleton
Creates/gets the singleton of this class. Parameters
| Name | Type | Description |
|---|---|---|
client | Client | The client to use |
mode | ShardingManagerMode | Mode the shard was spawned with |
Returns: ShardClientUtilSource
shardIdForGuildId
Get the shard id for a given guild id. Parameters
| Name | Type | Description |
|---|---|---|
guildId | Snowflake | Snowflake guild id to get shard id for |
shardCount | number | Number of shards |
Returns: numberSource