Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: Shard 0 not found #9830

Open
AleeQuintino opened this issue Sep 11, 2023 · 11 comments
Open

RangeError: Shard 0 not found #9830

AleeQuintino opened this issue Sep 11, 2023 · 11 comments

Comments

@AleeQuintino
Copy link

AleeQuintino commented Sep 11, 2023

Which package is this bug report for?

discord.js

Issue description

I'm getting an error when I try to change my bot's presence. My code changes the presence of several bots I have.

RangeError: Shard 0 not found
 at SimpleShardingStrategy.send (/application/node_modules/@discordjs/ws/dist/index.js:1205:13)
 at WebSocketManager.send (/application/node_modules/@discordjs/ws/dist/index.js:1448:26)
 at WebSocketManager.broadcast (/application/node_modules/discord.js/src/client/websocket/WebSocketManager.js:317:56)
 at ClientPresence.set (/application/node_modules/discord.js/src/structures/ClientPresence.js:25:22)
 at ClientUser.setPresence (/application/node_modules/discord.js/src/structures/ClientUser.js:125:33)
 at Timeout.presence [as _onTimeout] (/application/src/events/client/ready.js:123:25)

Code sample

const options =  [{
    type: ActivityType.Watching,
    text: 'O melhor bot do discord',
    status: 'online',
    url: 'https://www.twitch.tv/thegomesplay'
  },
  {
    type: ActivityType.Listening,
    text: 'Powered by: AG Solutions',
    status: 'online',
    url: 'https://open.spotify.com/playlist/3B1c58XQcDWB0RkVclrgev?si=65c6e088f9474dd4'
  },
  {
    type: ActivityType.Playing,
    text: '100% automático',
    status: 'dnd',
    url: 'https://www.youtube.com/'
  }]

  setInterval(presence, 6000 * 10)

  async function presence() {

    const option = Math.floor(Math.random() * options.length) // isso aqui é pra pegar um status aleatório dos 3 da lista

    await client.user.setPresence({
      activities: [{
        name: options[option].text,
        type: options[option].type,
        url: options[option].url
      }],
      status: options[option].status
    })

  }

This is in a loop where it runs every 60000 ms

Versions

"discord.js": "^14.12.1"

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

Message

Which gateway intents are you subscribing to?

Message

I have tested this issue on a development release

No response

@Jiralite
Copy link
Member

Are you really using no intents?

@AleeQuintino
Copy link
Author

Are you really using no intents?

I marked it wrong, I only use message intents

@Jiralite
Copy link
Member

  1. Show you instantiate your client (the full object)
  2. Do you call <Client>.login()?
  3. Is this code outside the ready event (if you have one)?
  4. If your project is open-source, please provide a link! If not, please show us your dependencies

@AleeQuintino
Copy link
Author

AleeQuintino commented Sep 11, 2023

  • Show you instantiate your client (the full object)
  • Do you call <Client>.login()?
  • Is this code outside the ready event (if you have one)?
  • If your project is open-source, please provide a link! If not, please show us your dependencies
const { Partials } = require("discord.js")
const { Client } = require('discord.js')
const myIntents = require('./intents')

module.exports = async function (token, data, clients, Discord) {

    clients[data.CLIENTID] = new Client({ intents: myIntents, partials: [Partials.Channel] })

    const handlers = ["event_handler"];

    handlers.forEach(async handler => {
        await require(`../handlers/${handler}`)(Discord, clients[data.CLIENTID], data);
    });

    try {
        await clients[data.CLIENTID].login(token);
        return { run: true, message: 'ok' }
    } catch (error) {
        clients.log.error(`error to starting the application`, { clientId: data.CLIENTID, error: error.code })
        return { run: false, message: `Client: ${data.CLIENTID} \nErro: ${error.code}` }
    }

}
  1. Yes, client.login() is being called normally and everything else works perfectly
  2. No, this code is within the ready event, as I run it when I start the project
 "dependencies": {
   "@discordjs/voice": "^0.15.0",
   "@fastify/autoload": "^5.7.1",
   "@fastify/jwt": "^6.7.1",
   "@fastify/rate-limit": "^8.0.3",
   "@logtail/node": "^0.4.5",
   "@logtail/winston": "^0.4.5",
   "axios": "^1.4.0",
   "discord.js": "^14.12.1",
   "dotenv": "^16.3.1",
   "fastify": "^4.21.0",
   "jsonwebtoken": "^9.0.1",
   "sequelize": "^6.32.1",
   "sqlite3": "^5.1.6",
   "uuid": "^9.0.0",
   "winston": "^3.10.0"
 }

@Jiralite
Copy link
Member

Could you provide a minimal code sample (bare minimum code to reproduce the error) we could use to debug ourselves? I'm not sure we can help out with the unknowns and complexities as seen in your code.

@AleeQuintino
Copy link
Author

AleeQuintino commented Sep 11, 2023

Could you provide a minimal code sample (bare minimum code to reproduce the error) we could use to debug ourselves? I'm not sure we can help out with the unknowns and complexities as seen in your code.

(async () => {

  const { Partials, Client } = require('discord.js')

  const db = [
    { CLIENTID: 'clientid1', TOKEN: 'token1' },
    { CLIENTID: 'clientid2', TOKEN: 'token2' },
    { CLIENTID: 'clientid3', TOKEN: 'token3' },
    { CLIENTID: 'clientid4', TOKEN: 'token4' }
  ]

  const clients = {}

  for (const key of db) {

    clients[key.CLIENTID] = new Client({ intents: 130809, partials: [Partials.Channel] })

    clients[key.CLIENTID].on('ready', (Discord, client) => {

      const options = [{
        type: ActivityType.Watching,
        text: 'O melhor bot do discord',
        status: 'online',
        url: 'https://www.twitch.tv/thegomesplay'
      },
      {
        type: ActivityType.Listening,
        text: 'Powered by: AG Solutions',
        status: 'online',
        url: 'https://open.spotify.com/playlist/3B1c58XQcDWB0RkVclrgev?si=65c6e088f9474dd4'
      },
      {
        type: ActivityType.Playing,
        text: '100% automático',
        status: 'dnd',
        url: 'https://www.youtube.com/'
      }]

      setInterval(presence, 6000 * 10)

      async function presence() {

        const option = Math.floor(Math.random() * options.length)

        await client.user.setPresence({
          activities: [{
            name: options[option].text,
            type: options[option].type,
            url: options[option].url
          }],
          status: options[option].status
        })

      }
    });

    await clients[key.CLIENTID].login(key.TOKEN)

  }

})();

@AleeQuintino
Copy link
Author

My code is separated by handlers and the bots' data is requested from an external database, but simply put, it is presented like this above

@Jiralite
Copy link
Member

I used the provided code sample and encountered no errors with 4 bots... so far? How long does it take to receive an error? Are you getting the error too with your code sample (which has minor errors in)?

@AleeQuintino
Copy link
Author

I run more than 4 bots, at the moment there are 763
This error takes about 15 minutes for this error to start appearing

@AleeQuintino
Copy link
Author

@Jiralite any feedback?

@didinele
Copy link
Member

didinele commented Oct 6, 2023

I used the provided code sample and encountered no errors with 4 bots... so far? How long does it take to receive an error? Are you getting the error too with your code sample (which has minor errors in)?

I run more than 4 bots, at the moment there are 763

It is not feasible for us to reproduce this problem. It's also not really all that intended to run so many bots under one process - despite us sort of making an effort to support multiple WebSocketManager instances existing within the same app - unless you can find an actual minimal reproduction sample, this issue is invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants