1

I have a discord bot, which just reached 2500 servers, and it stopped logging in, because apparently there is a limit of 2500 and then you need to use Sharding, which I'd never heard of until now.

So I added a ShardManager to my bot, as per tutorials:

const { ShardingManager } = require('discord.js');
const settings = require('./settings.json');

const manager = new ShardingManager('./bot.js', { token: settings.token });

manager.spawn();
manager.on('launch', shard => console.log(`Launched shard ${shard.id}`));

And now I launch the bot with that file instead, and I thoguht it was all working, but then the bot dropped out again and I received an email from discord saying they'd reset the token due to it logging in about 1000 times in 24 hours.

I tried starting the bot again and watched the output (as my error logs for forever node js don't seem to be working), and I got the error:

(node:2465) UnhandledPromiseRejectionWarning: Error: Shard 1's Client took too long to become ready.
    at Timeout.setTimeout [as _onTimeout] (/var/discord-WriterBot/node_modules/d                                                                                                iscord.js/src/sharding/Shard.js:89:31)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5)
(node:2465) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch                                                                                                 block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

Then the same thing for shard 2.

Am I doing something wrong with the ShardManager? I don't really understand it very well, but I believe I followed the instructions correctly.

This is the full bot code if it helps: https://github.com/cwarwicker/discord-WriterBot

Thanks.

CMR
  • 1,366
  • 4
  • 15
  • 31

1 Answers1

0

I was working through this error as well as the SHARDING_READY_DIED error for quite some time. In order to catch the error, you must add an error event listner during the shard creation process.

manager.on('shardCreate', async (shard) => {
  console.log('Shard Launched')
  shard.on('error', (error) => {
     console.error(error)
  })
})

If respawn is set to true on the sharding manager, the shard will automatically restart and the parent process will not crash.

tonestrike
  • 320
  • 6
  • 22