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.