Shard

export class Shard extends EventEmitter
export class Shard extends EventEmitter
A self-contained shard created by the ShardingManager. Each one has a 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
death(process)
Emitted upon the shard's child process/worker exiting.
NameTypeOptionalDescription
processChildProcessWorkerNoChild process/worker that exited
disconnect()
Emitted upon the shard's shardDisconnect event.
message(message)
Emitted upon receiving a message from the child process/worker.
NameTypeOptionalDescription
message*NoMessage that was received
reconnecting()
Emitted upon the shard's shardReconnecting event.
resume()
Emitted upon the shard's shardResume event.
spawn(process)
Emitted upon the creation of the shard's child process/worker.
NameTypeOptionalDescription
processChildProcessWorkerNoChild process/worker that was created
args:string[]
Arguments for the shard's process (only when is process)
env:unknown
Environment variables for the shard's process, or workerData for the shard's worker
execArgv:string[]
Arguments for the shard's process executable (only when is process)
id:number
The shard's id in the manager
Manager that created the shard
process:ChildProcess | null
Process of the shard (if is process)
ready:boolean
Whether the shard's Client is ready
silent:boolean
Whether to pass silent flag to the shard's process (only when is process)
worker:Worker | null
Worker of the shard (if is worker)
eval(script):Promise<unknown>
Evaluates a script or function on the shard, in the context of the Client.
Returns
Result of the script execution
NameTypeOptionalDescription
scriptstringNoJavaScript to run on the shard
fetchClientValue(prop):Promise<unknown>
Fetches a client property value of the shard.
NameTypeOptionalDescription
propstringNoName of the client property to get, using periods for nesting
kill():void
Immediately kills the shard's process/worker and does not restart it.
on(event, listener):this
NameTypeOptionalDescription
eventKNoNone
listener(...args: ShardEventTypes[K]) => Awaitable<void>NoNone
once(event, listener):this
NameTypeOptionalDescription
eventKNoNone
listener(...args: ShardEventTypes[K]) => Awaitable<void>NoNone
respawn(options?):Promise<ChildProcess>
Kills and restarts the shard's process/worker.
NameTypeOptionalDescription
options{ delay?: number; timeout?: number }YesOptions for respawning the shard
send(message):Promise<Shard>
Sends a message to the shard's process/worker.
NameTypeOptionalDescription
messageunknownNoMessage to send to the shard
spawn(timeout?):Promise<ChildProcess>
Forks a child process or creates a worker thread for the shard. You should not need to call this manually.
NameTypeOptionalDescription
timeoutnumberYesThe amount in milliseconds to wait until the Client has become ready before resolving (-1 or Infinity for no wait)