ClusterUtil
Extends EventEmitter
The main hub for creating clusters.
Constructor
new ClusterUtil(token, file, options);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
token | string | ❌ | undefined | Discord API Token. |
file | string | ❌ | undefined | Path to file containing Client code. |
options | ClusterUtilOptions? | ✔️ | undefined | Options for cluster util. |
Methods
isPrimary
Checks if the current process is the primary process.
isPrimary();
Returns
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);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
clusterId | number | ❌ | null | Cluster identifier. |
Returns
Promise< ClusterStats | undefined >
sendEvent
Sends an event to every cluster through events.
sendEvent(message);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
message | ProcessEventPartials | ❌ | undefined | Event Partials. |
Returns
void
sendEventTo
Sends an event to a certain cluster through events.
sendEventTo(clusterId, message);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
clusterId | number | ❌ | null | Clusters ID. |
message | ProcessEventPartials | ❌ | undefined | Event Partials. |
Returns
void
broadcast
Sends an IPC event to every cluster through ipc.
broadcast(message);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
message | IPCEvent | ❌ | undefined | IPC Event. |
Returns
void
sendTo
Sends an IPC event to a certain cluster through ipc.
sendTo(clusterId, message);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
clusterId | number | ❌ | null | Clusters ID. |
message | IPCEvent | ❌ | undefined | IPC Event. |
Returns
void
broadcastEval
Sends some code to every cluter to be evaulated then returns the results or errors.
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);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
callback | BroadcastEvalCallback | ❌ | undefined | Callback. |
references | object? | ✔️ | undefined | Variables 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);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
clusterId | number | ❌ | null | Cluster 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.
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
info | string | - | - | Info Event. |
Cluster_Util_Error
Usually sent when you write bad code that throws an error.
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
error | ClusterUtilError | - | - | Error Info. |
Cluster_Death
Sent when a cluster dies.
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
death | ClusterDeath | - | - | Death Info. |
Cluster_Error
Sent when a cluster errors out. Usually sent when you write bas code that throws an error.
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
error | ClusterError | - | - | Error Info. |
Cluster_Warn
Sent when a cluster encounters a warn usually somthing to do with DJS.
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
warn | ClusterWarn | - | - | Warn Info. |
Cluster_Ready
Sent when a cluster becomes ready.
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
ready | ClusterReady | - | - | Ready Info. |
Shard_Ready
Sent when a shard on a cluster becomes ready.
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
ready | ShardReady | - | - | Ready Info. |
Shard_Resume
Sent when a shard on a cluster resumes.
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
resume | ShardResume | - | - | Resume Info. |
Shard_Reconnecting
Sent when a shard on a cluster is reconnecting.
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
reconnecting | ShardReconnecting | - | - | Reconnecting Info. |
Shard_Disconnect
Sent when a shard on a cluster disconnects.
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
disconnect | ShardDisconnect | - | - | Disconnect Info. |
Shard_Error
Sent when a shard on a cluster encounters and error. Sent when your code sucks, you know the drill.
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
error | ShardError | - | - | Error Info. |