#[SHARDING_IN_PROCESS] Shards are still being spawned

51 messages · Page 1 of 1 (latest)

wraith venture
#

Hi 👋
How can I fix this error ?

app.js:

const config = require('./setup/config.json')

// ------------- Shard Management ------------------
const { ShardingManager } = require('discord.js');

const manager = new ShardingManager('./index.js', { token: config.token });

manager.on('shardCreate', shard => {
    console.log(`[SHARD] Shard ID ${shard.id}`)
});

manager.spawn();
short coyote
#

• 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.

wraith venture
gleaming rampart
#

what are you doing in your ready event

wraith venture
#

ready.js

module.exports = async (bot) => {

    bot.shard.fetchClientValues('guilds.cache.size').then(guilds => {
        bot.shard.fetchClientValues('users.cache.size').then(users => {
            const guildscount = guilds.reduce((prev, val) => prev + val, 0)
            const userscount = users.reduce((prev, val) => prev + val, 0)
            console.log("ONLINE !\nGuilds : " + guildscount + "\nUsers : " + userscount + "\n--------------------------------------------------------------------")
        })
    })

}
#

@gleaming rampart

gleaming rampart
#

yeah well

#

that's why

wraith venture
#

Why ?

gleaming rampart
#

in every shard that readies you query all shards for guild count

#

given what you do with that, that is very pointless

#

because you try to log the same value multiple times

#

just log guilds and users of the current shard, not all

wraith venture
#

Yes but I will have only users count and guilds count on the current shard and no on all shards thinKappa

gleaming rampart
#

what

wraith venture
#

What do you mean by log guilds and users of the current shard ? @gleaming rampart

gleaming rampart
#

just client.guilds.cache.size

#

don't do fetchClientValues

#

and btw, you don't have to ping me, i'm literally here

wraith venture
gleaming rampart
#

that's not how that works

#

client.shard is the current shard, yes

#

but none of the data is actually on the shard

#

but on the client

#

the functions on client.shard are for communication between shards

#

both broadcastEval and fetchClientValues

wraith venture
#

oh Okay

gleaming rampart
#

there's no guild or users or whatever

wraith venture
#

But when you want to fetch a guild, you must go through client.shard and no with client.guilds.fetch

gleaming rampart
#

why do you want to fetch a guild

wraith venture
#

To fetch members maybe, to obtain the guild name etc...

gleaming rampart
#

then do that with broadcastEval, but do what you need inside of it. do not take guilds or members out of that just to do things with the result locally

wraith venture
#

Ok thank you so much for your help
I have a last question

#

When I start my bot, I have a lot of console log to tell me what my bot is ONLINE..... and it continues

gleaming rampart
#

well yes

#

each shard has own client

#

and each client runs ready

wraith venture
#

Yes but I have only 2 shards (0 and 1)
Why I have a lot of console.log

gleaming rampart
#

well, show code

wraith venture
#

app.js

const config = require('./setup/config.json')

// ------------- Shard Management ------------------
const { ShardingManager } = require('discord.js');

const manager = new ShardingManager('./index.js', { token: config.token });

manager.on('shardCreate', shard => {
    console.log(`[SHARD] Shard ID ${shard.id}`)
});

manager.spawn();

ready.js

module.exports = async (bot) => {

    console.log("ONLINE !\nGuilds : " + bot.guilds.cache.size + "\nUsers : " + bot.users.cache.size + "\n--------------------------------------------------------------------")
}
gleaming rampart
#

and how do you call that ready file function

wraith venture
# gleaming rampart and how do you call that ready file function

With
index.js

const Discord = require('discord.js');
const myIntents = new Discord.Intents()
myIntents.add(Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_PRESENCES, Discord.Intents.FLAGS.GUILD_MEMBERS, Discord.Intents.FLAGS.GUILD_WEBHOOKS)
const Enmap = require('enmap')
const bot = new Discord.Client({
  autoReconnect: true,
  disableEveryone: true,
  intents: myIntents,
  partials: [
      "USER",
      "GUILD_MEMBER"
  ]
})
const PREFIX = "/";

const fs = require('fs')
const { token } = require('./setup/config.json')

fs.readdir('./events/', (err, files) => {
  if (err) return console.error(err)
  files.forEach(file => {
    const event = require(`./events/${file}`)
    const eventName = file.split('.')[0]
    bot.on(eventName, event.bind(null, bot))
    delete require.cache[require.resolve("./events/"+file)]
  })
})

bot.login(token)```
wraith venture
#

@gleaming rampart
Do you see anything that could cause this repetition in my console.log? 🤔
Thanks 🙂

wraith venture
#

Hi @gleaming rampart
Do you know where is the problem in my code or not ? Because Discord resets my token every day 😅
Thank you so much
See you later 😉

burnt knotBOT
#

Please add the following code to your code base outside of any other event listeners and provide the full log output relevant to your issue.

client
    .on("debug", console.log)
    .on("warn", console.log)

• Note: if you initialize your Client as bot or other identifiers you need to use these instead of client
• If the output is too long to post consider using a bin instead: gist | hasteb.in | sourceb.in | hastebin

sturdy depot
#

Use that to check if/when your client logs in again and again

wraith venture
sturdy depot
#

Or in other terms: where’s debug log of shard 0 spawning?

wraith venture
#

I found the problem, i was trying to start a second time my web server in my ready event and he couldn't start the shard because the webserver was putting an error