timotejroiko/discord.js-light

Shards: "auto" not working

Closed this issue · 4 comments

I have an application that delivery (now) 230 bots with same source code, the idea is to make code as generic as possible and keep it health to host. Your lib is helping me a lot, but I'm having problem to make shard works in automatic mode. Maybe there is a way to use ShardManager, but I would have to check which bot needs Shards or not, and rewrite a big part of the struct code (which isn't a problem, but maybe it doesn't scale so good).

In summary, shards: "auto" already solved my situation using discord.js main lib, BUT, costing me 2000% more RAM than your library.

Question: I'm doing something wrong or shards auto option (in ClientOptions params) isn't working?
PS: In rare cases it works, but in most part of time not.

Error [SHARDING_REQUIRED]: This session would have handled too many guilds - Sharding is required.
801|vps | at WebSocketManager.createShards (/root/fork-heroku-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:249:15)
801|vps | at async Client.login (/root/fork-heroku-bot/node_modules/discord.js/src/client/Client.js:245:7)
801|vps | at async upsetEvents (/root/fork-heroku-bot/dist/bot.js:336:21) {
801|vps | [Symbol(code)]: 'SHARDING_REQUIRED'
801|vps | }

const config = {

  intents: ["GUILD_MESSAGES"],

  makeCache: Discord.Options.cacheWithLimits({
    ApplicationCommandManager: 0, 
    BaseGuildEmojiManager: 0, 
    ChannelManager: 0, 
    GuildChannelManager: 0, 
    GuildBanManager: 0, 
    GuildInviteManager: 0, 
    GuildManager: Infinity, 
    GuildMemberManager: 0,
    GuildStickerManager: 0, 
    MessageManager: 0, 
    PermissionOverwriteManager: 0,
    PresenceManager: 0, 
    ReactionManager: 0,
    ReactionUserManager: 0, 
    RoleManager: 0, 
    StageInstanceManager: 0, 
    ThreadManager: 0, 
    ThreadMemberManager: 0, 
    UserManager: 0, 
    VoiceStateManager: 0 
  })
}
const Discord = require("discord.js-light")

...
some code here
...

discordApiKey.forEach((_) => this.client.push(new Discord.Client({
      ...config,
      shards: "auto"
})))

Why are you creating multiply clients and pushing them in a array
djs-light does not modify the internal structure of the sharding manager.
And there is not a ram difference, when comparing the sharding. Since they are the same.

I would look at new Sharding Options such as Clustering, some good pkgs there on npm.

And your code is wrong.
You want to use Internal Sharding?
Then:
• Remove the push part
• Its shardCount: "auto", leave the shards property empty, since it accepts a array of shard ids.

shards: "auto" should work, there is no reason for it not to work...

can you check the debug event?

this.client reference doesn't means anything about discord.js-light, is just the way I got to manage my collection, anyway my use case is it https://cryptoalarm.xyz/, its different bots that are deployed dynamic. I need multiple instances cuz are literally multiple discord applications.

shards: "auto" should work, there is no reason for it not to work...
can you check the debug event?

After some hours trying to understand why sometimes it works, sometimes not, maybe problem was create 200 instances with shards auto. Now, i'm just filtering with couple bots and creating shards only for who needs it, looks like working image

i'll close this issue, very thx for quickly answer, and really awesome project