ClusterManager

new ClusterManager(file, optionsopt)

Parameters:
NameTypeAttributesDescription
filestring

Path to your bot file

optionsobject<optional>

Options for the cluster manager

Properties
NameTypeAttributesDefaultDescription
totalShardsstring | number<optional>
'auto'

Number of total internal shards or "auto"

totalClustersstring | number<optional>
'auto'

Number of total Clusters\Process to spawn

shardsPerClustersnumber<optional>

Number of shards per cluster

shardArgsArray.<string><optional>
[]

Arguments to pass to the clustered script when spawning (only available when using the process mode)

execArgvArray.<string><optional>
[]

Arguments to pass to the clustered script executable when spawning

respawnboolean<optional>
true

Whether clusters should automatically respawn upon exiting (only available when using the process mode)

modeClusterManagerMode<optional>
'worker'

Which mode to use for clustering

shardListArray.<number><optional>

A Array of Internal Shards Ids, which should get spawned

tokenstring<optional>

Token to use for automatic internal shard count and passing to bot file

restartsobject<optional>

Restart options

Properties
NameTypeAttributesDescription
intervalnumber<optional>

Interval in milliseconds on which the current restarts amount of a cluster will be resetted

maxnumber<optional>

Maximum amount of restarts a cluster can have in the interval

queueobject<optional>

Control the Spawn Queue

Properties
NameTypeAttributesDefaultDescription
autoboolean<optional>
true

Whether the spawn queue be automatically managed

Members

clusterData :object

Data, which is passed to the workerData or the processEnv

Type:
  • object

clusterList :Array.<number>

A Array of IDS[Number], which should be assigned to the spawned Clusters

Type:
  • Array.<number>

clusterOptions :object

Options, which is passed when forking a child or creating a thread

Type:
  • object

clusters :Collection.<number, Cluster>

A collection of all clusters the manager spawned

Type:

execArgv :Array.<string>

An array of arguments to pass to the executable (only when ClusterManager#mode is process)

Type:
  • Array.<string>

file :string

Path to the bot script file

Type:
  • string

mode :ClusterManagerMode

Mode for shards to spawn with

Type:
  • ClusterManagerMode

respawn :boolean

Whether clusters should automatically respawn upon exiting

Type:
  • boolean

restarts :Object

How many times a cluster can maximally restart in the given interval

Type:
  • Object

shardArgs :Array.<string>

An array of arguments to pass to clusters (only when ClusterManager#mode is process)

Type:
  • Array.<string>

shardList :string|Array.<number>

List of internal shard ids this cluster manager spawns

Type:
  • string | Array.<number>

shardsPerClusters :number

Amount of Shards per Clusters

Type:
  • number

(nullable) token :string

Token to use for obtaining the automatic internal shards count, and passing to bot script

Type:
  • string

totalClusters :number

Amount of total clusters to spawn

Type:
  • number

totalShards :number

Amount of internal shards in total

Type:
  • number

Methods

_debug(message, cluster) → {string}

Logs out the Debug MessagesUsing this method just emits the Debug Event.This is usually not necessary to manually specify.

Parameters:
NameTypeDescription
message
cluster
Returns:

returns the log message

Type: 
string

broadcast(message) → {Promise.<Array.<Cluster>>}

Sends a message to all clusters.

Parameters:
NameTypeDescription
message*

Message to be sent to the clusters

Returns:
Type: 
Promise.<Array.<Cluster>>

broadcastEval(script, optionsopt) → {Promise.<*>|Promise.<Array.<*>>}

Evaluates a script on all clusters, or a given cluster, in the context of the Clients.

Parameters:
NameTypeAttributesDefaultDescription
scriptstring | function

JavaScript to run on each cluster

optionsObject<optional>
{}

The options for the broadcastEVal

Returns:

Results of the script execution

Type: 
Promise.<*> | Promise.<Array.<*>>

createCluster(id, shardsToSpawn, totalShards) → {CLUSTER}

Creates a single cluster.Using this method is usually not necessary if you use the spawn method.This is usually not necessary to manually specify.

Parameters:
NameTypeDescription
id
shardsToSpawn
totalShards
Returns:

Note that the created cluster needs to be explicitly spawned using its spawn method.

Type: 
CLUSTER

extend()

Adds a plugin to the cluster manager

fetchClientValues(prop, clusteropt) → {Promise.<*>|Promise.<Array.<*>>}

Fetches a client property value of each cluster, or a given cluster.

Parameters:
NameTypeAttributesDescription
propstring

Name of the client property to get, using periods for nesting

clusternumber<optional>

Cluster to fetch property from, all if undefined

Returns:
Type: 
Promise.<*> | 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(optionsopt) → {Promise.<Collection.<number, Cluster>>}

Kills all running clusters and respawns them.

Parameters:
NameTypeAttributesDescription
optionsClusterRespawnOptions<optional>

Options for respawning shards

Returns:
Type: 
Promise.<Collection.<number, Cluster>>

triggerMaintenance(reason)

Parameters:
NameTypeDescription
reasonstring

If maintenance should be enabled on all clusters with a given reason or disabled when nonce provided

Events

clusterCreate

Emitted upon creating a cluster.

Parameters:
NameTypeDescription
clusterCluster

Cluster that was created

debug

Emitted upon receiving a message

Parameters:
NameTypeDescription
Message,string

which was received