I am trying to shard my discord bot in v13, and when I run just the main file (bot.js) on my beta bot without sharding, it works fine, but when I try running it with sharding, It gives this error.
Here is the index.js code where I shard
const { ShardingManager } = require('discord.js'); const manager = new ShardingManager('./bot.js', { token: 'tokenhere' }); manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`)); manager.spawn();
When I try running just bot.js without sharding, it gives the error that says too many guilds on one session, meaning the main file is fine.
Here is the main file code
I don’t think there are any errors on this file. Please let me know how to fix this, and how to shard properly
Advertisement
Answer
You are running node .
which if I am not mistaken starts all the .js files in the folder you are in.
What happens is that both index.js
and bot.js
files are started.
You must run ONLY the file where the ShardingManager is, with node index.js
.