Need Help with Launching Multiple Shards Simultaneously in Discord.js

Hello everyone, I'm currently working on a relatively large bot that utilizes more than 200 shards. We're receiving a max_concurrency of 16 from Discord. Discord.js has been our go-to library from day one, and I can't express my gratitude enough to the developers and the community for making it incredibly easy to develop a bot. Lately, I've been experimenting with deploying multiple shards simultaneously. According to the Discord docs on Sharding, it should be possible. However, I've run into a bit of an issue. Despite my efforts, it seems like discord.js still waits approximately 5 seconds before initiating each shard, regardless of the delay being set to 0. Here's the code snippet I've been experimenting with:
async function startShards(group) {
// Start sharding
const mode = 'process';
const manager = new ShardingManager(bot, {
token: TOKEN,
shardList: group,
totalShards: totalShards,
mode: mode
});
manager.on('shardCreate', shard => console.log(`ShardManager: Shard ${shard.id} launched`));
await manager.spawn({delay: 0});
console.log(`Launched group: ${group}`);
}
async function startShards(group) {
// Start sharding
const mode = 'process';
const manager = new ShardingManager(bot, {
token: TOKEN,
shardList: group,
totalShards: totalShards,
mode: mode
});
manager.on('shardCreate', shard => console.log(`ShardManager: Shard ${shard.id} launched`));
await manager.spawn({delay: 0});
console.log(`Launched group: ${group}`);
}
An example value for group is [16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]. Even with the delay set to 0, it seems the library is launching one shard at a time with an interval of around 5 seconds between each launch. I'm starting to wonder if there's an oversight on my part or a misuse of the ShardingManager. Any guidance or assistance on this matter would be highly appreciated. Thank you all for your continued support! Let me know if this is good to go, or if there are any changes you'd like me to make!
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
3 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
nihilisticwhale
nihilisticwhaleOP2y ago
I'm using [email protected] @Mod is there any way to get this question answered by a contributor to the library? Thanks so much!
monbrey
monbrey2y ago
Not by pinging us I'm not an expert on sharding by any means but I'm pretty sure Discord imposes a rate limit of 5 seconds per identify, with each shard needing to identify to spin up. You cant have it at 0
Want results from more Discord servers?
Add your server