export class ShardingManager extends EventEmitter
This is a utility class that makes multi-process sharding of a bot an easy and painless experience. It works by spawning a self-contained ChildProcess or Worker for each individual shard, each containing its own instance of your bot's Client. They all have a line of communication with the master process, and there are several useful methods that utilise it in order to simplify tasks that are normally difficult with sharding. It can spawn a specific number of shards or the amount that Discord suggests for the bot, and takes a path to your main bot script to launch for each one.
Constructors
file: stringoptions?: ShardingManagerOptions)
constructor(An array of arguments to pass to the executable (only when mode is process
)
string file :
Path to the shard script file
ShardingManagerMode mode :
Mode for shards to spawn with
boolean respawn :
Whether shards should automatically respawn upon exiting
number[] | 'auto' shardList :
List of shards this sharding manager spawns
Collection<number, Shard> shards :
A collection of shards that this manager has spawned
number | 'auto' totalShards :
Amount of shards that all sharding managers spawn in total
broadcastEvalResult
>() : Promise<Serialized<Result>[]> <
Result
Evaluates a script on all shards, or a given shard, in the context of the Clients.
Returns: Results of the script execution
Creates a single shard. Using this method is usually not necessary if you use the spawn method.
Returns: Note that the created shard needs to be explicitly spawned using its spawn method.
respawnAlloptions?: MultipleShardRespawnOptions) : Promise<Collection<number, Shard>> (
Kills all running shards and respawns them.
spawnoptions?: MultipleShardSpawnOptions) : Promise<Collection<number, Shard>> (
Spawns multiple shards.
shardCreateshard: Shard) (
Emitted upon creating a shard.