mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Add ShardingManager#send and ShardingManager#broadcast (#730)
* add ShardingManager#send and ShardingManager#broadcast * make gawdl3y happy * Fix a thing
This commit is contained in:
committed by
Schuyler Cebulskie
parent
e86b93b34f
commit
edd174a5eb
File diff suppressed because one or more lines are too long
@@ -73,6 +73,24 @@ class ShardingManager extends EventEmitter {
|
||||
else this.createShard();
|
||||
}, 5500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to a shard by ID.
|
||||
* @param {number} id ID of the shard to send the message to
|
||||
* @param {*} message Message to send to the shard
|
||||
*/
|
||||
send(id, message) {
|
||||
if (!this.shards.has(id)) throw new Error('Shard ID is invalid!');
|
||||
this.shards.get(id).process.send(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast a message to all shards.
|
||||
* @param {*} message Message to be sent to the shards
|
||||
*/
|
||||
broadcast(message) {
|
||||
for (const shard of this.shards.values()) shard.process.send(message);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ShardingManager;
|
||||
|
||||
Reference in New Issue
Block a user