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
Emitted upon the shard's child process/worker exiting.
NameTypeOptionalDescription
processChildProcess | WorkerNoChild process/worker that exited
disconnect
Emitted upon the shard's event.
message
Emitted upon receiving a message from the child process/worker.
NameTypeOptionalDescription
messageanyNoMessage that was received
resume
Emitted upon the shard's event.
spawn
Emitted upon the creation of the shard's child process/worker.
NameTypeOptionalDescription
processChildProcess | WorkerNoChild process/worker that was created
args:string[]
Arguments for the shard's process/worker
Environment variables for the shard's process, or workerData for the shard's worker
execArgv:string[]
Arguments for the shard's process/worker executable
The shard's id in the manager
Manager that created the shard
process:ChildProcess | null
Process of the shard (if mode 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 mode is process)
worker:Worker | null
Worker of the shard (if mode 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.
Example
shard.fetchClientValue('guilds.cache.size')
.then(count => console.log(`${count} guilds in shard ${shard.id}`))
.catch(console.error);
shard.fetchClientValue('guilds.cache.size')
.then(count => console.log(`${count} guilds in shard ${shard.id}`))
.catch(console.error);
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
eventEventNoNone
listener(...args: ShardEventTypes[Event]) => voidNoNone
once(event, listener):this
NameTypeOptionalDescription
eventEventNoNone
listener(...args: ShardEventTypes[Event]) => voidNoNone
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)