ClusterClient

new ClusterClient(client)

Parameters:
NameTypeDescription
clientClient

Client of the current cluster

Members

client :Client

Client for the Cluster

Type:

(readonly) count :number

Total number of clusters

Type:
  • number

(readonly) id :number

cluster's id

Type:
  • number

(readonly) ids :Map.<number, any>

Array of shard IDs of this client

Type:
  • Map.<number, any>

(readonly) info :object

Gets several Info like Cluster_Count, Number, Total shards...

Type:
  • object

maintenance :String

If the Cluster is under maintenance

Type:
  • String

mode :ClusterManagerMode

Mode the Cluster was spawned with

Type:
  • ClusterManagerMode

queue :Object

If the Cluster is spawned automatically or with a own controller

Type:
  • Object

Methods

(static) getInfo() → {Object}

gets the total Internal shard count and shard list.

Returns:
Type: 
Object

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

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

Parameters:
NameTypeDescription
scriptstring | function

JavaScript to run on each cluster

optionsobject

Some options such as the TargetCluster or the Eval timeout

Properties
NameTypeAttributesDefaultDescription
contextnumber<optional>

The Context to pass to the eval script

clusternumber<optional>

The Id od the target Cluster

shardnumber<optional>

The Id od the target Shard, when the Cluster has not been provided.

guildIdnumber<optional>

The Id od the guild the cluster is in, when the Cluster has not been provided.

timeoutnumber<optional>
10000

The time in ms to wait, until the eval will be rejected without any response

Returns:

Results of the script execution

Type: 
Promise.<*> | Promise.<Array.<*>>
Example
client.cluster.broadcastEval('this.guilds.cache.size')
  .then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`))
  .catch(console.error);

(async) evalOnManager(script, options) → {Promise.<*>|Promise.<Array.<*>>}

Evaluates a script or function on the Cluster Manager

Parameters:
NameTypeDescription
scriptstring | function

JavaScript to run on the Manager

optionsobject

Some options such as the Eval timeout or the Context

Properties
NameTypeAttributesDefaultDescription
timeoutnumber<optional>
10000

The time in ms to wait, until the eval will be rejected without any response

contextany<optional>

The context to pass to the script, when providing functions

See
  • ClusterManager#evalOnManager
Returns:

Result of the script execution

Type: 
Promise.<*> | Promise.<Array.<*>>
Example
client.cluster.evalOnManager('process.uptime')
  .then(result => console.log(result))
  .catch(console.error);

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
client.cluster.fetchClientValues('guilds.cache.size')
  .then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`))
  .catch(console.error);

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

Sends a Request to the ParentCluster 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);

respawnAll(optionsopt) → {Promise.<void>}

Requests a respawn of all clusters.

Parameters:
NameTypeAttributesDescription
optionsClusterRespawnOptions<optional>

Options for respawning shards

Returns:

Resolves upon the message being sent

Type: 
Promise.<void>

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

Sends a message to the master process.

Parameters:
NameTypeDescription
message*

Message to send

Fires:
  • Cluster#event:message
Returns:
Type: 
Promise.<void>

spawnNextCluster() → {Promise.<*>}

Manually spawn the next cluster, when queue mode is on 'manual'

Returns:
Type: 
Promise.<*>

triggerMaintenance(maintenance, all) → {String}

Parameters:
NameTypeDefaultDescription
maintenanceString

Whether the cluster should opt in maintenance when a reason was provided or opt-out when no reason was provided.

allBooleanfalse

Whether to target it on all clusters or just the current one.

Returns:

The maintenance status of the cluster.

Type: 
String

Events

message

Emitted upon receiving a message from the parent process/worker.

Parameters:
NameTypeDescription
message*

Message that was received