Discord.js: Feature Requests for Sharding (forceShutdown, on('shard_exit')[Event])

Created on 8 Apr 2018  Â·  7Comments  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:
Currently I have a Large Scale Bot, and I've run into some Issues.
The Bot I have will Join Quite a bit of Servers over the Course of a Month. Naturally hitting the 2500 Cap for Sharding Sometimes Several Times in a Month.
When the Current Shards Exit, there is no Event to Trigger their Exit. So for example if I have the respawn: true, in my ShardManager Options it will continously launch Shards over and Over again. But a Issue i'm facing is what if the Shard has hit Max Amount allowed? If there are 4 Shards, and they ahve 10,000 servers between them, and 1 of them Joins 10,001 that shard will disconnect and D.js will be in a Loop trying to bring it back online. Now.

I was told to make a Call when I hit that Sharding Limit and then do a Process.exit via BroadcastEval but again, this would trigger the "Respawn" functionality of the Shard Manager, and thus all the Shards would be stuck in a infinite Loop. Currently there is no way to get any notification on the Main Sharding Script, from the Shards that tell if it is Exiting, or if it has Crashed. Maybe pass a Event "shard_exit" with the Associated Errorcode, Or simply implement a 4011 Check and force all Shards to Close, then Reopen them with the Correct Amount of Shards.

i would like to Request a 'forceShutDown' command that would ignore the 'respawn' option in the Settings.

Or maybe a 'reShard' command which would recheck the Amount of Servers, and Properly restart the Shards with the New Limits.

Or simply give us a .on('shard_exit') event which would be used as a way to keep track of when the Shard Exits. Or a .on('shard_disconnects') event which would be just as awesome, allowing us to get the 4011 check and launch additional shards for it.

Include a reproducible code sample here, if possible:

var config = require('./config.json');

var Djs = require('discord.js');
var sharder = new Djs.ShardingManager(`${__dirname}/bot.js`, {
  totalShards: "auto",
  respawn: true,
  token: config.test ? config.discord.testToken : config.discord.secretToken
});

sharder.spawn();

sharder.on('launch', function(shard) {
  console.log(`Shard[${shard.id}] has Connected`);
});

Further details:

  • discord.js version: all
  • node.js version:
  • Operating system: Windows / Linux / Mac
  • Priority this issue should have – please be realistic and elaborate if possible: Quite High?

  • [ ] I found this issue while running code on a __user account__

  • [x] I have also tested the issue on latest master, commit hash:
sharding enhancement

Most helpful comment

I can see the case for making a ShardingManager#killAll() and/or Shard#kill(); while this is currently possible, it's not possible without using some private methods.

To listen to shard death, attach an event listener to the shard (documentation).

All 7 comments

Master branch already has a lot of the functionality you've described in the Shard class. I understand that relying on master branch in production comes with its own issues, but there is unlikely to be a backported release of these features soon. It sounds like you should be killing all shards and calling ShardingManager#spawn again to recalculate the recommended shard count. You should consider spawning more shards than necessary in order to make these occurrences less frequent.

This comes with a Drawback, again if you have 'respawn' enabled in the Options and you kill All Shards, it'll Be caused in a Loop.

There needs to be a way to Kill all Shards, without Triggering the 'respawn' option. And if you don't have it on, and a shard dies. You have no way of knowing, and no way of reLaunching it. Just gotta wait till someone reports its down? @Lewdcario said that same issue when they didnt remember to enable respawn, and couldnt figure out why the shards kept dieing.

We either need some sort of Event, trigger for when the Shard goes down. Or we need a way to Stop all Shards, so we can respawn them with the correct Number.

I can see the case for making a ShardingManager#killAll() and/or Shard#kill(); while this is currently possible, it's not possible without using some private methods.

To listen to shard death, attach an event listener to the shard (documentation).

Well how would I add a Event Listener to the Shard, when I use a ShardManager to Launch the Shards via .spawn?

@appellation Can you also Tag in for a killAll() that would ignore the respawn? Please?

@appellation I made a Edit too your Reference https://github.com/appellation/discord.js/pull/1

Resolved with #2454.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Blumlaut picture Blumlaut  Â·  3Comments

shukriadams picture shukriadams  Â·  3Comments

PassTheMayo picture PassTheMayo  Â·  3Comments

xCuzImPro picture xCuzImPro  Â·  3Comments

Dmitry221060 picture Dmitry221060  Â·  3Comments