#How to kill a shard and prevent its auto respawn functionnality?
31 messages · Page 1 of 1 (latest)
- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
✅Marked as resolved by OP
What’s the use case here?
The goal is that when my API asks the manager to stop a shard it stops it
Actually I have that as the code :
let shard = manager.shards.get(shardId);
if (shard) {
await promisifiedLog(`Stopping shard ${shardId}...`);
shard.process.kill(); // Arrête le processus du shard
shardsActive = shardsActive.filter(i => i !== shardId); // Retire du tableau des shards actifs
ShardingManagerOptions#respawn @14.16.1
Whether shards should automatically respawn upon exiting
But why would you want to do that in the first place?
As I am using multiple servers to host my bot, there are multiple shardingManager working together
but
discord.js is not made for this
it's made for only one execution of a shardingManager
and so it's possible that when restarting the shardingManager simultaneously that some of them takes the same shard and so a shard could be launched 2 times
Discord.js is perfectly made for that. You just need to pass the array of shardIds each one should handle in their constructor
ShardingManagerOptions#shardList @14.16.1
List of shards to spawn or "auto"
Yep but
the problem is that
if one shardingManager shutdown
the shards are stopped and these shards are abandonned
so the servers on these shards cannot access the bot anymore ?
And how is that related to two sharding managers serving the same shards on restart?
Well, you need to have an intermediate between the shardingManagers right ?
So that if one's down we can restart another
Maybe I m doing this wrong, I don't know
If one’s down (and unable to restart for whatever reason; that in itself would need an investigation how that could happen in the first place) you should start an instance somewhere else that serves the same shards, yes. But then you‘d only need to kill the whole ShardingManager process and all its shards. Not a single shard
You're right for that
But I think that the difference and the thing I didn't told you is that all shardingManager have a number of max shards they can handle but I don't want them to use this max number by default, only when it's necessary. So my API tells to the shardingManagers that are avaialable to receive a shard to launch a shard. But, if we reload the API, it doesn't know which ones are started so it gets all the shards already launched and at this moment others shardingManager could take shards that are already launched somewhere else and so if a manager tries to start a shard that is already launched the API tells him to stop
well
by writing this I m thinking that maybe there's something to do to prevent launching shards before getting already launched shards but not sure how to do that