Shard
classe · deprecated · Source
A self-contained shard created by the ShardingManager. Each one has a ChildProcess that contains an instance of the bot and its Client. When its child process/worker exits for any reason, the shard will spawn a new one to replace it as necessary.
Extends: EventEmitter
Properties
manager
Manager that created the shard Source
id
The shard's id in the manager Source
args
Arguments for the shard's process (only when ShardingManager#mode is process) Source
execArgv
Arguments for the shard's process executable (only when ShardingManager#mode is process) Source
env
Environment variables for the shard's process, or workerData for the shard's worker Source
ready
Whether the shard's Client is ready Source
process
Process of the shard (if ShardingManager#mode is process) Source
worker
Worker of the shard (if ShardingManager#mode is worker) Source
_evals
Ongoing operations for calls to Shard#eval, mapped by the script they were called with Source
_fetches
Ongoing operations for calls to Shard#fetchClientValue, mapped by the prop they were called with Source
_exitListener
Listener function for the ChildProcess' exit event Source
Methods
spawn
Forks a child process or creates a worker thread for the shard. You should not need to call this manually. Parameters
| Name | Type | Description |
|---|---|---|
timeout? | number | The amount in milliseconds to wait until the Client has become ready before resolving ( -1 or Infinity for no wait) Default: 30000. |
Returns: Promise<ChildProcess>Source
kill
Immediately kills the shard's process/worker and does not restart it. Source
respawn
Kills and restarts the shard's process/worker. Parameters
| Name | Type | Description |
|---|---|---|
options? | ShardRespawnOptions | Options for respawning the shard |
Returns: Promise<ChildProcess>Source
send
Sends a message to the shard's process/worker. Parameters
| Name | Type | Description |
|---|---|---|
message | * | Message to send to the shard |
Returns: Promise<Shard>Source
fetchClientValue
Fetches a client property value of the shard. Parameters
| Name | Type | Description |
|---|---|---|
prop | string | Name of the client property to get, using periods for nesting |
Returns: Promise<*>
shard.fetchClientValue('guilds.cache.size')
.then(count => console.log(`${count} guilds in shard ${shard.id}`))
.catch(console.error);eval
Evaluates a script or function on the shard, in the context of the Client. Parameters
| Name | Type | Description |
|---|---|---|
script | string | function | JavaScript to run on the shard |
context? | * | The context for the eval |
Returns: Promise<*> — Result of the script execution Source
_createPendingOperation
Creates an IPC operation that can be cleaned up and rejected if the child exits. Parameters
| Name | Type | Description |
|---|---|---|
operations | Map<string, Object> | Collection that owns the operation |
key | string | Operation identifier |
messageKey | string | IPC message property used for the identifier |
Returns: Promise<*>Source
_handleMessage
Handles a message received from the child process/worker. Parameters
| Name | Type | Description |
|---|---|---|
message | * | Message received |
| Source |
_handleExit
Handles the shard's process/worker exiting. Parameters
| Name | Type | Description |
|---|---|---|
respawn? | boolean | Whether to spawn the shard again Default: this.manager.respawn. |
timeout? | number | The amount in milliseconds to wait until the Client has become ready ( -1 or Infinity for no wait) |
| Source |
incrementMaxListeners
Increments max listeners by one for a given emitter, if they are not zero. Parameters
| Name | Type | Description |
|---|---|---|
emitter | EventEmitter | process | The emitter that emits the events. |
| Source |
decrementMaxListeners
Decrements max listeners by one for a given emitter, if they are not zero. Parameters
| Name | Type | Description |
|---|---|---|
emitter | EventEmitter | process | The emitter that emits the events. |
| Source |
Events
spawn
Emitted upon the creation of the shard's child process/worker. Parameters
| Name | Type | Description |
|---|---|---|
process | ChildProcess | Worker | Child process/worker that was created |
| Source |
ready
Emitted upon the shard's Client#event:shardReady event. Source
disconnect
Emitted upon the shard's Client#event:shardDisconnect event. Source
reconnecting
Emitted upon the shard's Client#event:shardReconnecting event. Source
message
Emitted upon receiving a message from the child process/worker. Parameters
| Name | Type | Description |
|---|---|---|
message | * | Message that was received |
| Source |
death
Emitted upon the shard's child process/worker exiting. Parameters
| Name | Type | Description |
|---|---|---|
process | ChildProcess | Worker | Child process/worker that exited |
| Source |