Skip to main content

ClusterUtil

Extends EventEmitter

The main hub for creating clusters.

Constructor

new ClusterUtil(token, file, options);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
tokenstringundefinedDiscord API Token.
filestringundefinedPath to file containing Client code.
optionsClusterUtilOptions?✔️undefinedOptions for cluster util.

Methods

isPrimary

Checks if the current process is the primary process.

isPrimary();

Returns

boolean


getStats

Returns stats on every cluster and the shards it contains etc.

getStats();

Returns

Promise< ClusterStats[] >


getStatsFrom

Returns stats on a specfic cluster and the shards it contains etc.

getStatsFrom(clusterId);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
clusterIdnumbernullCluster identifier.

Returns

Promise< ClusterStats | undefined >


sendEvent

Sends an event to every cluster through events.

sendEvent(message);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
messageProcessEventPartialsundefinedEvent Partials.

Returns

void


sendEventTo

Sends an event to a certain cluster through events.

sendEventTo(clusterId, message);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
clusterIdnumbernullClusters ID.
messageProcessEventPartialsundefinedEvent Partials.

Returns

void


broadcast

Sends an IPC event to every cluster through ipc.

broadcast(message);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
messageIPCEventundefinedIPC Event.

Returns

void


sendTo

Sends an IPC event to a certain cluster through ipc.

sendTo(clusterId, message);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
clusterIdnumbernullClusters ID.
messageIPCEventundefinedIPC Event.

Returns

void


broadcastEval

Sends some code to every cluter to be evaulated then returns the results or errors.

note

The callback may only contain references outside of the callback if you pass them as "references" where they will be scoped into context.

broadcastEval(callback, references);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
callbackBroadcastEvalCallbackundefinedCallback.
referencesobject?✔️undefinedVariables to reference in context.

Returns

Promise< BroadcastEvalResponse[] >


disposeOf

Sends a request to specified cluster to dispose itself. Will result in the cluster exiting with code 0 and being automatically restarted by ClusterUtil.

disposeOf(clusterId);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
clusterIdnumbernullCluster identifier.

Returns

void


launch

Starts the util.

launch();

Returns

void


Events

Cluster_Util_Info

Sends general debug info for telling when a cluster is ready or whatnot.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
infostring--Info Event.

Cluster_Util_Error

Usually sent when you write bad code that throws an error.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
errorClusterUtilError--Error Info.

Cluster_Death

Sent when a cluster dies.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
deathClusterDeath--Death Info.

Cluster_Error

Sent when a cluster errors out. Usually sent when you write bas code that throws an error.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
errorClusterError--Error Info.

Cluster_Warn

Sent when a cluster encounters a warn usually somthing to do with DJS.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
warnClusterWarn--Warn Info.

Cluster_Ready

Sent when a cluster becomes ready.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
readyClusterReady--Ready Info.

Shard_Ready

Sent when a shard on a cluster becomes ready.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
readyShardReady--Ready Info.

Shard_Resume

Sent when a shard on a cluster resumes.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
resumeShardResume--Resume Info.

Shard_Reconnecting

Sent when a shard on a cluster is reconnecting.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
reconnectingShardReconnecting--Reconnecting Info.

Shard_Disconnect

Sent when a shard on a cluster disconnects.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
disconnectShardDisconnect--Disconnect Info.

Shard_Error

Sent when a shard on a cluster encounters and error. Sent when your code sucks, you know the drill.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
errorShardError--Error Info.