Skip to content
Advertisement

Shard Dying Over and Over Discordjs

I am trying to shard my bot in discord.js. Client.js is my bot.js file

I have this code in my index.js file to shard

const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./structures/Client.js', {
   token: "token",
})

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

But I keep getting this error:

(node:27636) UnhandledPromiseRejectionWarning: Error [SHARDING_READY_DIED]: Shard 0’s process exited before its Client became ready.

I need some help on sharding it properly

Advertisement

Answer

There are a couple problems I would like to address that might be causing your issue

  • Your bot is attempting to be ran before it receives the ready event (@MrMythical)
  • The file is being recognized as a Class and not a script (@Logan Devine)

Running before the “ready” event

When your bot is receiving data from Discord and starting up, it’s not ready to start executing code. Discord has to do stuff on their end to make sure that you receive the correct data you’re supposed to receive. That’s why the ready event was created. If your bot tries to execute code before the ready event is emitted, it will exit. Likely, this is what is occcuring with your bot. It’s trying to run code before Discord has sent the ready event.

To fix this, it’s fairly simple. Just place this in your Client.js file and the bot will listen for the ready event

// Replace <client> with whatever variable your Client is
<client>.on("ready", async () => {
  console.log("Online!")
})

Recognizing as a Class

You’ve named the file with a capital letter. This is typically done when creating a Class. However, you’re trying to run a script. To fix this, just rename your file with a lowercase letter. If you want to keep the “Client” name on it, just change the uppercase “C” to a lowercase “c”. This should resolve the issue

Other Issues

There is one last issue I would like to address. You might be referencing a file that has bad code. Ensure that the Client.js inside the structures folder has the correct code because you may be accessing the wrong file.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement