Constructor
new ShardingManager(file, optionsopt)
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
file |
string | Path to your shard script file | |||||||||||||||||||||||||||||||||||||||||
options |
Object |
<optional> |
Options for the sharding manager
Properties
|
- Source:
Extends
- EventEmitter
Members
execArgv :Array.<string>
An array of arguments to pass to the executable (only when ShardingManager#mode is `process`)
Type:
- Array.<string>
- Source:
file :string
Path to the shard script file
Type:
- string
- Source:
mode :ShardingManagerMode
Mode for shards to spawn with
Type:
- Source:
respawn :boolean
Whether shards should automatically respawn upon exiting
Type:
- boolean
- Source:
shardArgs :Array.<string>
An array of arguments to pass to shards (only when ShardingManager#mode is `process`)
Type:
- Array.<string>
- Source:
shardList :string|Array.<number>
List of shards this sharding manager spawns
Type:
- string | Array.<number>
- Source:
shards :Collection.<number, Shard>
A collection of shards that this manager has spawned
Type:
- Collection.<number, Shard>
- Source:
(nullable) token :string
Token to use for obtaining the automatic shard count, and passing to shards
Type:
- string
- Source:
totalShards :number
Amount of shards that all sharding managers spawn in total
Type:
- number
- Source:
Methods
broadcast(message) → {Promise.<Array.<Shard>>}
Sends a message to all shards.
Parameters:
Name | Type | Description |
---|---|---|
message |
* | Message to be sent to the shards |
- Source:
Returns:
- Type
- Promise.<Array.<Shard>>
broadcastEval(script) → {Promise.<Array.<*>>}
Evaluates a script on all shards, in the context of the Clients.
Parameters:
Name | Type | Description |
---|---|---|
script |
string | JavaScript to run on each shard |
- Source:
Returns:
Results of the script execution
- Type
- Promise.<Array.<*>>
createShard(idopt) → {Shard}
Creates a single shard.
Using this method is usually not necessary if you use the spawn method.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
id |
number |
<optional> |
this.shards.size | ID of the shard to create
|
- Source:
Returns:
Note that the created shard needs to be explicitly spawned using its spawn method.
- Type
- Shard
fetchClientValues(prop) → {Promise.<Array.<*>>}
Fetches a client property value of each shard.
Parameters:
Name | Type | Description |
---|---|---|
prop |
string | Name of the client property to get, using periods for nesting |
- Source:
Returns:
- Type
- Promise.<Array.<*>>
Example
manager.fetchClientValues('guilds.cache.size')
.then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`))
.catch(console.error);
(async) respawnAll(shardDelayopt, respawnDelayopt, spawnTimeoutopt) → {Promise.<Collection.<string, Shard>>}
Kills all running shards and respawns them.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
shardDelay |
number |
<optional> |
5000 | How long to wait between shards (in milliseconds) |
respawnDelay |
number |
<optional> |
500 | How long to wait between killing a shard's process and restarting it (in milliseconds) |
spawnTimeout |
number |
<optional> |
30000 | The amount in milliseconds to wait for a shard to become ready before continuing to another. (-1 or Infinity for no wait) |
- Source:
Returns:
- Type
- Promise.<Collection.<string, Shard>>
(async) spawn(amountopt, delayopt, spawnTimeoutopt) → {Promise.<Collection.<number, Shard>>}
Spawns multiple shards.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
amount |
number | string |
<optional> |
this.totalShards | Number of shards to spawn |
delay |
number |
<optional> |
5500 | How long to wait in between spawning each shard (in milliseconds) |
spawnTimeout |
number |
<optional> |
30000 | The amount in milliseconds to wait until the Client has become ready before resolving. (-1 or Infinity for no wait) |
- Source:
Returns:
- Type
- Promise.<Collection.<number, Shard>>
Events
shardCreate
Emitted upon creating a shard.
Parameters:
Name | Type | Description |
---|---|---|
shard |
Shard | Shard that was created |
- Source: