Cluster

A self-contained cluster created by the ClusterManager. Each one has a Child that contains an instance of the bot and its Client. When its child process/worker exits for any reason, the cluster will spawn a new one to replace it as necessary.

Constructor

new Cluster(manager, id, shardList, totalShards)

Parameters:
NameTypeDescription
managerClusterManager

Manager that is creating this cluster

idnumber

ID of this cluster

shardList
totalShards

Extends

  • EventEmitter

Members

args :Array.<string>

Arguments for the shard's process (only when ShardingManager#mode is process)

Type:
  • Array.<string>

env :object

Environment variables for the cluster's process, or workerData for the cluster's worker

Type:
  • object

execArgv :Array.<string>

Arguments for the shard's process executable (only when ShardingManager#mode is process)

Type:
  • Array.<string>

id :number

ID of the cluster in the manager

Type:
  • number

manager :ClusterManager

Manager that created the cluster

shardList :number

Internal Shards which will get spawned in the cluster

Type:
  • number

thread :Child|Worker

Process of the cluster (if ClusterManager#mode is process)

Type:
  • Child | Worker

totalShards :number

the amount of real shards

Type:
  • number

Methods

(async) eval(script, context, timeout) → {Promise.<*>}

Evaluates a script or function on the cluster, in the context of the Client.

Parameters:
NameTypeDescription
scriptstring | function

JavaScript to run on the cluster

context
timeout
Returns:

Result of the script execution

Type: 
Promise.<*>

kill(options)

Immediately kills the clusters's process/worker and does not restart it.

Parameters:
NameTypeDescription
optionsobject

Some Options for managing the Kill

Properties
NameTypeDescription
forceobject

Whether the Cluster should be force kill and be ever respawned...

request(message) → {Promise.<*>}

Sends a Request to the ClusterClient and returns the reply

Parameters:
NameTypeDescription
messageObject

Message, which should be sent as request

Returns:

Reply of the Message

Type: 
Promise.<*>
Example
client.cluster.request({content: 'hello'})
  .then(result => console.log(result)) //hi
  .catch(console.error);

(async) respawn(optionsopt) → {Promise.<Child>}

Kills and restarts the cluster's process/worker.

Parameters:
NameTypeAttributesDescription
optionsClusterRespawnOptions<optional>

Options for respawning the cluster

Returns:
Type: 
Promise.<Child>

send(message) → {Promise.<Shard>}

Sends a message to the cluster's process/worker.

Parameters:
NameTypeDescription
message* | BaseMessage

Message to send to the cluster

Returns:
Type: 
Promise.<Shard>

(async) spawn(spawnTimeoutopt) → {Promise.<Child>}

Forks a child process or creates a worker thread for the cluster.You should not need to call this manually.

Parameters:
NameTypeAttributesDefaultDescription
spawnTimeoutnumber<optional>
30000

The amount in milliseconds to wait until the Client has become ready before resolving. (-1 or Infinity for no wait)

Returns:
Type: 
Promise.<Child>

triggerMaintenance(reason)

Parameters:
NameTypeDescription
reasonstring

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

Events

death

Emitted upon the cluster's child process/worker exiting.

Parameters:
NameTypeDescription
processChild | Worker

Child process/worker that exited

error

Emitted upon the cluster's child process/worker error.

Parameters:
NameTypeDescription
processChild | Worker

Child process/worker, where error occurred

ready

Emitted upon the cluster's Client#ready event.

spawn

Emitted upon the creation of the cluster's child process/worker.

Parameters:
NameTypeDescription
processChild | Worker

Child process/worker that was created