#archive-sharding
12465 messages · Page 11 of 13
Well I'm currently working on a dashboard for my bot, but I want to get the guilds and show them on the website. I didnt require the client and it gives this error: ```
node:internal/process/promises:265
triggerUncaughtException(err, true /* fromPromise */);
^
DiscordHTTPError: 401 Unauthorized on GET /api/v9/users/@me/guilds
show ur code
401 means the token is invalid
Make sure it's prefixed correctly and ur using the user's access token
aight will do, thanks
I cant really find the issue, everything seems normal. The issue is apparently on line 28.
and here I'm requesting the token in login.js
I'm manually respawning the WebsocketShard
ohh boy, I went through it too. The pr would help you with it 😄
btw I wrote a script to replace the files in node_modules/discord.js with the code in pr. I just set it up once and respawn all of them. Works fine so far. There is a better solution to it, I will have that pushed in my pr in few days and then merge it into main
figured I'd ask here as it's related to multi process bots
any way to share rate limit data between the bots? if one process hits a rate limit I don't want another process to then hit 429s that could've been prevented
was thinking some redis thing but honestly no clue where I need to look
It currently isn't possible. We are in the process of splitting up d.js into modules that would allow you to do that
I'll put that on some imaginary list for next year then
or whenever it happens
I was able to do this using external ipc, If one shard or process hits a 429 all other shards/processes on the network are informed
Hopefully with new ws module of vlad, Ig he will cover this in it
const Discord = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('pp')
.setDescription('p!')
.addBooleanOption(option => option
.setName('reply')
.setDescription('reply؟'))
,
execute(interaction, client, retEph) {
try {
let embed = new Discord.MessageEmbed()
// ...
interaction.channel.send({ embeds: [embed] }).catch((err) =>console.log("Err-PP: " + err));
} catch (er) {
console.log("caErr-Pray: " + er)
},
};
``` the bot send 5 messages!! how to fix it
also in guildCreate event it send 5 messages
sometimes 2 or 3
Judging by the code you probably have multiple instances running
i've nothing
it's happing from a week or more
could it be because of replit?
Possibly, do you have any sharding or anything running?
Ah wait, stupid question we’re in the sharding channel, unless you just crossposted

idk i’m guessing just reset your bot token and update it in replit as that will destroy all other instances of your bot, but if that doesn’t work I don’t have the slightest idea
Please don’t say you host a sharding bot on replit…
I don’t, I don’t even use sharding, but this suggested that they’re bot was being hosted on replit and it was using sharding, I suggested an idea for them which im not sure would work because i’ve never been in a scenario like that
Oh, I totally missed that message mentioning replit. My bad🤦♂️
replit is okay for small to medium sized bots. But once you’re so big that you need sharding you should switch to something more reliable
okay so my bot requires tonna user response from messages, Since message content is being phased out im using DMs for that, But since all user DMS are on shard 0 the so the "MessageCollector" only really works with commands that are initiated on guilds that are on shard 0, Anyway i can get MessageCollector work in shards other than 0 in DMs
You could use broadcastEval with shard 0 so it only broadcasts to shard 0 aka DMs and those guilds, and you could add a filter to the collector
const manager = new ShardingManager('./bot.js', {
token: process.env.token
});``` this will work fine
const manager = new ShardingManager('./bot.js', {
totalShards: 2, // !
token: process.env.token
});
manager.on('shardCreate', s=> console.log(`Launched shard ${s.id}`));
``` but this will spam the console
Probably because of replit
Yup, your shards get respawned quite often because of replit instability
Had this issue today where a shard would receive no heartbeat in time and destroying the shard and reconnecting but after this message here I did not receive any heartbeat from shard 12 ever again https://i.altpapier.dev/M4bs0mwWfU.png . I had a look with ws.status and ws.ping but ws.status shows 0 for READY and ws.ping shows the same ping every single time I try and ping it. Any idea how this issue can be solved to not happen in the future?
how do i get the total number of voice channel connections across all shards?
require("dotenv").config();
const { ShardingManager , Client} = require("discord.js")
const colors = require("colors")
const shards = new ShardingManager("./index.js" , {
token : process.env.token,
totalShards : "auto",
respawn : true,
delay : 20000,
timeout : 60000
})
shards.on("shardCreate" , async (shard) => {
console.log(`[${new Date().toString().split(" ", 5).join(" ")}] Launched Shard #${shard.id}`.bold.green)
})
shards.on("disconnect" , async (shard) => {
console.log(`[${new Date().toString().split(" ", 5).join(" ")}] Disconnected Shard #${shard.id}`.bold.red)
})
shards.on("death" , async (shard) => {
shards.spawn(shards.totalShards , 10000);
console.log(`[${new Date().toString().split(" ", 5).join(" ")}] Killed Shard #${shard.id}`.bold.red)
})
shards.spawn(shards.totalShards , 10000);
why there’s nothing in console
shards.spawn takes an object as parameter, not two parameters
Documentation suggestion for @vale basin:
ShardingManager#spawn()
Spawns multiple shards.
The same way you get all guildMembers across all shards, adjust the example from the guide to VC instead
any idea what this is about
Adding too many message listeners to a childprocess
anyone got any idea? This happened to me again now
i only have one. i remember hearing somewhere that it might involve broadcasteval but idk for sure, and i've cut down on its usage anyways
I think broadcastevals do count towards those as well not 100% sure tho. If you have a couple broadcastevals running at the same time that could be it ig
const express = require("express");
const app = express();
app.get('/', (req, res) => {
res.send('Hello Express app!')
});
app.listen(3000, () => {
console.log('Bot started');
});```
it will log err: `address already in use :::3000`
i think because shard 0 will use it then shard 1 will return the err
i did this but same err
```js
app.listen(3001 || 3002 || 3003, ()```
how is express related to djs sharding?
just listen on sharding manager or shard 0 only
because it works fine without sharding
how to listen on shard 0 only 👀
bro literally just do the express server in the file where you invoke your shards and not in the file where the bot is
oh ok thank you very much!! Is that bug also present in d.js v13.5 bc dont really use the features of .6 would be cool if that fixed that as well for now
it existed in v12 aswell
oh ok guess its just been an issue for me since a couple days weird
Some huge bot devs said, due to this issue they switched to other js libraries. But now we know the issue. The fix I implemented works but its not the best one. I need to push a better solution to that
we suffered this issues for months which had me debug ws and discord.js library We used to restart the shard manually
did that the last couple days as well I currently have a bot with 20 shards and hate it to debug stuff like that to find the reason for it
well I debugged it https://github.com/discordjs/discord.js/issues/7450
here is the eexact issue ⤴️ Maybe removing presence intent from the bot fix it automatically.
I dont think I have the presence intent rn will just copy paste what you have currently in the pr. Thanks for helping me with that 👍
your using v13?
yea v13.6 currently and desperately waiting for v13.7 lol sorry I gotta go sleep now back tmr
can i make a shard for every 5 server not every 2500 server ?
You could if you wanted to, tho you may be restarting quite often depending on ur growth and may have some shards that have no guilds
Please don’t shard. You need a way better understanding of JS and d.js before trying sharding
k
Is sharding every 5 servers even useful 
Nope
Easy way to waste cpu and consume login rate limits
one shard has about 1000 guilds btw, not 2500
discord recommends you to start sharding at 2500
yes but thats not what they were talking about
Bot not spawning new shards automatically
In some servers it don't work
So we have to restart when we need to make a new shard?
That sucks cuz we r growing really fast rn
You can spawn 1shard per 500 Guilds, will allow you 2000 Guilds extra per shard.
Ok how would I control that?
We grow like 500-600 Guilds per day
How would I make it so I have to restart it every week or so @next plaza
And I want to use your discord hybrid sharding thing for sharding.
With the shardCount property.
Come to dms, against rules here talking about 3rd party stuff.
guys, is there a way to get in ready event the shard id ?
client.shard.ids[0]
?
i don't asking this, i'm asking how to get the shard id with the client parameter in the ready event
yes
that gives you the shard id of the client
this just gave me all the shards ids
no, im using it, it works
i want the shard id where the event is executed
yes thats exectly what it does
example console output
so the nb in "SHARD .." is client.shard.ids[0] ?..
yes
it seems strange to me but I will try
How many guilds are on each shard? I thought its about 1000 but i have like 2200 now and its still 2 not 3 shard, when will the 3rd shard be created?
is there's anything i need to change in command handler after sharding?
because it duplicates messages on replit and if using VSC
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
if (interaction.guild && interaction.channel.type == "GUILD_VOICE") return;
try {
await command.execute(interaction, client);
} catch (error) {
console.error(error);
return interaction.reply({ content: 'ERR!!', ephemeral: true });
}
});
you probably exported your client and imported it somewhere else, this look like you have 2 process running
log something on the event and check if it's logged twice
it's not
i've this issue from 10 days
sometimes it send 3 times or 4 or 5
that does look like duplicated processes to me
i just generated new token
same issue
no lol
not like that
you are probably somewhere importing your client (requiring your bot file) which worked before sharding, but now youll have to import the manager and then use broadcastEval @terse cairn

I’ve the manager in index.js
All Codes in bot.js
Why do i need broadcastEval
i dont know what you're doing, how am I supposed to know. the problem you described looks like you're running multiple instances of the client, you can achieve that by (for example) importing your client in a different file (const client = require("/bot.js").client, e.g.)
that would have worked before but with sharding, its creating another instance
you would need broadcastEval to do what you did before with the imported client

const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./bot.js', {
// totalShards: 2,
token: process.env.token
});
manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
manager.spawn({ timeout: -1 })
.catch(console.error);
// module.exports = { manager }
``` this’s `index.js`
and the Client and other things works fine in bot.js but it duplicate messages and almost everything.
Do i need to import manager?
@vestal sluice
no, you dont understand me
the problem is not that file
Agree
one of your bot files probably imports client
but since the bot.js file was never actually run, it runs it and creates a second instance of the client
I’m dying
Duplicate messages
My bot just doesn't work on some shards
It's weird with shards my bot just doesn't do anything on some servers
How to fix
it may require to resharding, which need to restart the bot
Nope it's not that
As some of the servers aren't new and I have 8 shards so
And my bot is in 4k servers it just grew by 100
do debugging
Is it possible to use auto in the sharding Manager and only change it so that shard 0 recives only half the guilds? I want to do that because there will be some stuff only run on Shard 0 and it will have a bigger payload
You can't control which guilds go to which shards, it’s determined by the sharding formula
Unless you become so popular that Discord has to distribute the guilds in a more equal manner
I don't want to control what guilds go where, I just want to control how many goes where
you cant..... well you can change shard count that would increase or decrease guilds per shard
Okay, the thing is that I just got an awnser to a question I didn't ask and My real question got ignored :) but still thanks to everybody who helps here
how was it ignored? you got replied twice. and heres third reply: no, you cant control how many guilds are there per shard
I spoke about the first awnser
yk who was ignored, me lmao
You should try resharding
did already restart, didnt change anything
@unborn ingot
Try Looking through the threads if you find something, if not maybe the search function reveals a solution to you
Hey, does someone know how to perform good clustering with discord.js bots?
I think there was a extra nom package that did quite a good job and also allows it to be combined with internal sharding
if you mean running multiple sharding managers, then just specify which shards you want to spawn by specifying shardList in your shardingmanager options
I have 8 shards and I'm in 4000 guilds so that should work right? But this happens in some servers pls help
Thank you very much
I've seen some which one would you recommend?
how can you be sure it is about sharding?
Becuz the command works in every guild except a couple
And other stuff doesn't work in their server
Like pinging the bot to talk but the weird thing is that the bot is online in their server
Never used one myself yet, only heated about them
you should debug a bit more
try using catch() where you create the shards
also can u show me ur sharding file
Can 1 user be in more than 1 shard?
yes
are there any other options for clustering besides kurasuta?
Hello, i am using discord.js 13 and have a question regarding sharding and database connections.
Currently i have 80 shards running, all using their own connection pool to a single mysql database. As i cache a lot of results, the database usage of every shard goes down after start. So at some point i have way more connections than needed, which takes a lot of ram on the database vps.
Now i would like to tunnel all db requests through the sharding manager's connection pool (is this a good idea?), but i can only find a broadcastEval function, where i can send messages to all shards. Is there a way to request-response (with async await) from one shard to the shardingManager only? How is this done?
Hey! How i can return structures such as Collections in a broadcastEval?
Yep, at the end of the broadcastEval you can add
}, { shard: shard.id }
So how do i address the shardingManager? i want to send a message from a shard to the shardingmanager.
Documentation suggestion for @formal ivy:
ShardClientUtil#send()
Sends a message to the master process.
And send your answer via Shard#message. Need to create a listener on both ends for the message event
Yea, its simple
client.shard.send()
You can’t, because broadcastEval works with passing JSON between processes. So you can only get raw JSON objects, not instances of classes
Okey! Any other fix? Or only jsons?
What’s the use-case you want it for? Might be easier to provide fixes if I know the goal you try to accomplish
can i await this client.shard.send() to respond with data from the shardingmanager, while still "being in" the handling of the interaction in the shard?
or will i have to, for instance, send the channelId of the user writing the command in the payload, and setup a new listener in the shard itself.
Yep! I have this Collection
current: {
track: 'test'
title: 'test3',
identifier: 'kh1sF-sbkbw',
isStream: false,
displayThumbnail: [Function: bound displayThumbnail],
requester: GuildMember {
guild: [Guild],
joinedTimestamp: 1625738691136,
premiumSinceTimestamp: null,
nickname: null,
pending: false,
communicationDisabledUntilTimestamp: null,
_roles: [Array],
user: [User],
avatar: null
}
},
previous: null
]```
And i want to return it in a broadcastEval, so later i can update the queue in another shard after it gets reloaded
Like im savinf that Object and i want to keep it after i respawn a shard, so for that i want to save it
You can await it, but the resolved promise will return void. It doesn’t work like a remote function call but more like a dialogue.
So what i do is a broadcastEval to the shard i am going to restart and i throws me back this Object
GuildMembers are only valid in the Guild they are in and a guild is always only on one shard. So don’t really see why you‘d need to send a GuildMember anywhere
Just because when it restarts i want the music keep playing, so i need the person who request that music
Ah, so you just want to save it so it can be reloaded after restart? Why not use database of any kind instead of trying to broadcastEval?
So how can i receive the answer from the shardingmanager, to respond to the user's interaction?
Only way i can think of right now, is having a "bucket" inside the shard, where i throw the answers into, while in the handling of the interaction i will loop for a certain amount of time and regularly check if my answer is already in that "bucket"
Because i need the exact data before restart it, and im saving the data in real time in client.manager.players
And if i save it in a database i need to update the database like every 5 seconds, imagine update a database on 100 shards every 5 seconds
Tbh I‘d say that inter-process-communication like you try to do here won‘t be faster or less heavy on your resources than simply keeping a DB connection on every shard
The thing is, i am pretty confident that the amount of connections is the next limit i am facing. While this wont be a problem for a while still, it is the only thing that keeps me from simply firing up new databases, which would be nice, as the database is doing a lot of calculation for me. i can simply add databases from the logical perspective. but if i have lets say 1.000 shards, each connecting to 10 databases, thats 10.000 connections. wont this be a problem?
Why would you connect to more than one database per shard? What do the other 9 databases do that the first couldn’t?
Because the distribution of guilds changes with the amount of shards. one guild that is on shard 0 one day, might be on a completely different shard the other day. This means that all shards need connections to all databases
Why can’t all data be in one database though?
That’s what databases are made for. To have your data in one place accessible from many different places
Theres a reason why there is somethign called a sharded database... because a database also has its limits and bottlenecks
Yes, but if that was the case for you then how would introducing your ShardingManager as new bottleneck help with that in any way? You said that after some time you mostly do read operations on the database anyway, then replication would do the same trick without need of sharded DB
my bot is a statistics bot and the strain on the database is significant. the database does a lot of calculation. aside from the database. if all shards on one vps would share one connection, i could easily fire up new databases.
At 80 Shards, you should cluster your bot. You will save a lot of ram and less connections to the db.
splitting the shards on multiple vps' wont reduce the number of connections, if every shard has its own connection
Put multiply ws shards in one process, can be controlled with the shardCount and shards property on the client constructor.
is that "internal sharding"?
Yeah, basically many processes internal sharded
by what factor can i reduce it that way? like 10 shards in one process? or more?
Based on your load 8-16 Ws Shards
hmm that approach should work for a looooong time, but its depending on the amount of databases i add.
Maybe switching to a other db such as pgsql, mariadb or even a nonsql ones
would those really make a difference?
i thought if i switch, it would be a document based, mongod, which comes with built in sharding possibilities. but the problem is with document based i would have to rethink all the calculations going on on the database level.
I think I figured it out
If a user uses the settings command in a voice channel it breaks it for the shard
Nvm
Yup, #769862166131245066 text in VC is an evil thing discord did
the only thing that i can suspect is that guild is for some reason unavailable for the bot, check guild.available on it
its when someone tries
to use buttons in a vc channel\
theres no errors must be an internal error
so is it SOMEONE or GUILD issue?
its a vc channel issue...
we are talking about "interaction failed"
its the new text channel vcs. the bug is u cant use buttons in them, it breaks the bot. stops the process
see what i am replying to
its not an error with my code, it onyl happens in vc channels.
and it doesn't error in the terminal
even tho i used try and catch
i am talking about application commands, not vcs nor buttons
its when na button is used in a vc text channel
whats ur djs version
13
^13.6.0
voice text channels arent supported in it afaik
how do i install version 13.3.1
wdym
discord js version 13.3.1
remove and install it
it says +
anyways it says those versions do not crash soo
It says they do not crash upon message receiving. They do crash on ButtonInteractions though
oh well ^
thats your issue then
Simply check if it’s a VC before creating buttons in it
And it won’t crash
hello! ive just made a very simple discord bot and i *think* i want to implement sharding. basically i want different servers to be like different instances and not share variables which i believe is where sharding should help. currently my variables are being shared across servers which im trying to get rid of. the below code is my index.js but my bot seems to keep sharing variables. can anyone help? :)
require('dotenv').config();
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./src/bot2.js', { token: process.env.DISCORDJS_BOT_TOKEN });
manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
manager.spawn();```
You are misunderstanding the purpose of sharding. It is not necessarily to have different data across guilds, as that is extremely inconsistent and creates multiple issues due to bad code; the purpose of sharding is to split the bot's load onto multiple different threads in order to have better ping/responsiveness for all guilds. In addition, sharding is only recommended at around 2000 guilds anyway, so it might not be right for you to shard just yet.
If you want different data for guilds, I suggest storing the ids & data in a database or JSON file (may be unstable).
I can answer any other questions about sharding if you have any.
Thanks for the clarification Dylan. Do you have any recommendations to get started on integrating with a database? Also, is there anyway to find out which server a message is being sent on? (Please let me know if we should switch to another channel)
It's fine staying in this channel:
To figure out which server a message is being sent on, considering you are using a messageCreate listener, you could use <message>.guild. (if you are listening interactions, that would be <interaction>.guild)
As for databases, it depends on how you are planning to use your bot. If you are using it for a single, smaller guild, I would suggest JSON files to store data (using fs read and write). Though, if you plan for your but to be in multiple servers with a good amount of data, I'd highly suggest MongoDB - its a very simple document based db, which is free for most use-cases.
Thank you Dylan. You've been very helpful. I'm quite new to Discord.js. Thanks again :)
No problem! Have fun learning Discord.js!
Sorry real quick before I stop bothering you 😅. is there anyway to list all the servers (or "guilds") the bot is currently on?
Absolutely no worries!
In order to get all the guilds the bot is in, you would use <client>.guilds.cache
To put that in a readable format, as that would be a massive list of all guilds with all their data, we can use "map".
Using <client>.guilds.cache.map(g => ...) we can display certain snippets of data about each guild, and it will be conjoined in a nice, clean message. For example we can use:
<client>.guilds.cache.map(g => `${g.name} : ${g.id}`)
This displays a nice list of all guilds, but to make it even better, we can join each guild's data with a new line, using .join('\n')
All of this code together will create a nice list of all the guilds the bot is in:
// The Code:
<client>.guilds.cache.map(g => `${g.name} : ${g.id}`).join('\n')
// Possible Output:
`
ServerOne : 49288348023948
ServerTwo : 98209850293530
ServerThree : 78302855291530
`
Thanks again! That worked perfectly!
Np! Good luck with your bot!
Does internal sharding (specifying shards: "auto" in ClientOptions) also only shows the users managed in the current shard when using UserManager.cache
No, internal sharding only makes several WS instances to handle the API load, but all caches etc. are shared between all instances since it’s a single process running.
Why is there an error (zombie connection) and that the required number of guilds was not obtained within 15 seconds.. This happens when GUILD_PRESENCES intention is enabled, without it everything runs fine and the shards successfully connect to the gateway without any reconnection.
GUILD_PRESENCES I hope?
🤠
Hey, I released my bot to production and after a while I get this error. I cant figure out what causes it.
is there a way to check where the error really originated?
are there any other options for clustering besides kurasuta?
If probably originates in one of your broadcastEval calls where you return an instance of a class instead of plain JSON
Why the shard gose down?
Does it respawn or not?
Not
Ye I've been getting the same close code 4009 (updating djs helped me)
Weird, 4009 is session timeout and should lead to reconnect…
Which djs Version?
latest
Give me a number. What does npm ls discord.js give you?
How check shard is online or offline
"discord.js": "^13.6.0",```
That’s only what your package.json says, not the actual version you have installed…
Internal or traditional sharding?
What you mean?
Do you have a ShardingManager?
Yes
Really weird in that case… No idea then
Then use fetchClientValues('ws.status') and you even get an array of all shards and if they are online
Well, you might get no result if it’s offline, but that’s as good as false to know it’s not online
🙂
Unless you got ratelimited on login calls
I am getting some ratelimits from fetching messages
this maybe it idk
@crisp flicker not 100% sure tho if that solves ur issue
Why my bot replies twice when i shard my bot? My bot is in 70 servers, ik its less but all my friends do it at 30-50 servers. They get it to work, but when i shard my bot replies twice :(
show your sharding config?
wait
const { ShardingManager } = require("discord.js"); const logger = require(`${process.cwd()}/modules/logger.js`); foxieShardingManager = class extends ShardingManager { //shardingManager };
const shardingManager = new foxieShardingManager(`${process.cwd()}/index.js`, { totalShards: 5, respawn: true, mode: "process", token: process.env.DISCORD_TOKEN, execArgv: ["--trace-deprecation", "--trace-warnings"] }); shardingManager.on("shardCreate", (shard) => console.log(`Shard ${shard.id} Initiated...`)); try { shardingManager.spawn({timeout: -1}); } catch(e) { console.log("Sharding Manager Error", e) } logger.color("yellow").log("-".repeat(15), "SHARDINGMANAGER LOADED", "-".repeat(15));
^^
how to send him 1 message if he's in 2 shards
thanks i will try
if i'm using a command in a guild that in shard 1
and i want the bot to reply with the server name of a server in shard 2
how to do it 
fetch the guild first
or channel
do i need to use broadcastEval?
no just do it with js const guild = await client.guilds.fetch(id)
worked, but if i put wrong id, it will log err missing access while i'm doing
if (!guild) return console.log("NoSERVER");
fixed, شكرا
because its throw rejection. also why do you need to fetch them? its will stay available after ready state.
@snow sierra
basically you want to send message to channel on other shard?
elaborate
I want to get a server name that might be in other shard and send it in the same channel that i used the command in
it worked with fetch
why dont use broadcastEval? or if you using fetch you have to catch the rejection if its does not exist
how to do it with broadcastEval
reject(new Error('SHARDING_READY_TIMEOUT', this.id));
^
Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.
at Timeout.onTimeout (/home/container/node_modules/discord.js/src/sharding/Shard.js:163:16)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
[Symbol(code)]: 'SHARDING_READY_TIMEOUT'
It’s a method of client.shard
Hey, what does this error mean? what error message key?
and how would I fix this?
Looks like you have a recursive call on a shard messaging function. Either broadcastEval or send directly judging by the line numbers it might be fetchClientValues. Do you try to fetchClientValues('shard') or something along those lines? Or do you listen on the 'message' event in ShardingManager and send something back there that calls a function that will fetchClientValues again?
hey sorry to bother ya but can you please send me that lib ?
let guilds = await manager.fetchClientValues('guilds.cache.size')
let players = await manager.fetchClientValues('music.sPlayers')
those are the only fetchCLientValues I have in the code. I have custom client class and music is another class with sPlayers property being a collection of classes
A collection of classes sounds bad. The fetchClientValues can only return JSON
yes thats all right, it serializes
I need to get guildID property from each instance and how many instances there is
when it converts to json its an object with the guildID property and its an array so I can get the length
I‘d still advise to only fetch values that are plain JSON things to reduce the chances or weird side effects like the ones you are facing
How many guilds are on each shard? I thought its about 1000 but i have like 2200 now and its still 2 not 3 shard, when will the 3rd shard be created?
asked this a while ago and didnt receive a proper answer, so im asking again, now with almost 2300 servers and still 2 shards. i did restart
its about 1000 if you dont set the shard count manually
as i said, thats what i thought as well, but why do I still only have 2 shards then?
show the options you're using on the shardingmanager
new ShardingManager('./src/bot/index.js', { token: TOKEN });
nothing special
and you restarted that file?
it starts together with the bot, so yes
make a GET /gateway/bot request to the discord api using your bots token on the authorization header and show the result
curl example: curl -H "Authorization: Bot YOUR_BOTS_TOKEN" https://discord.com/api/v9/gateway/bot
{"url": "wss://gateway.discord.gg", "shards": 2, "session_start_limit": {"total": 1000, "remaining": 994, "reset_after": 59599842, "max_concurrency": 1}}
ok, discord suggest that your bot uses 2 shards, thats why the shardingmanager is only creating 2 shards
but why? i thought its 1000 per shard
¯_(ツ)_/¯
[WS => Shard 20] Heartbeat acknowledged, latency of 121ms.
[WS => Shard 0] [CLOSE]
Event Code: 1000
Clean : false
Reason :
[WS => Shard 0] Clearing the heartbeat interval.
[WS => Shard 0] WS State: CLOSED
[WS => Shard 26] Heartbeat acknowledged, latency of 202ms.
[WS => Shard 28] [CLOSE]
Event Code: 1000
Clean : false
Reason :
[WS => Shard 28] Clearing the heartbeat interval.
[WS => Shard 28] WS State: CLOSED
[WS => Shard 30] [CLOSE]
Event Code: 1000
Clean : false
Reason :
[WS => Shard 30] Clearing the heartbeat interval.
[WS => Shard 30] WS State: CLOSED
[WS => Shard 18] [CLOSE]
Event Code: 1000
Clean : false
Reason :
[WS => Shard 22] Clearing the heartbeat interval.
[WS => Shard 22] WS State: CLOSED
[WS => Shard 17] [CONNECTED] Took 359ms
[WS => Shard 17] Clearing the HELLO timeout.
[WS => Shard 17] Setting a heartbeat interval for 41250ms.
[WS => Shard 17] [RESUME] Session f7296839c553980131d684ff0bdde3a5, sequence 1446
[WS => Shard 17] Tried to send packet '{"op":6,"d":{"token":"NzXndXIUssnXij36A3OTgxODQ2AjPx.X_bEg.51QMzR2OF41NARLksUYYd6G4GpyoWk","session_id":"f7296839c553986784340131d684ff0bdde3a5","seq":1425}}' but no WebSocket is available!
[WS => Shard 17] [DESTROY]
Close Code : 4000
Reset : false
Emit DESTROYED: true
[WS => Shard 17] Clearing the heartbeat interval.
[WS => Shard 17] Shard was destroyed but no WebSocket connection was present! Reconnecting...
My bot is online but not responding to commands and I get these weird messages in client.on('debug') event.
that message contains your bots token, might want to reset it
lmao
you can ignore that
but tell me what's the error
[WS => Shard 20] Heartbeat acknowledged, latency of 121ms.
[WS => Shard 0] [CLOSE]
Event Code: 1000
Clean : false
Reason :
[WS => Shard 0] Clearing the heartbeat interval.
[WS => Shard 0] WS State: CLOSED
[WS => Shard 26] Heartbeat acknowledged, latency of 202ms.
[WS => Shard 28] [CLOSE]
Event Code: 1000
Clean : false
Reason :
[WS => Shard 28] Clearing the heartbeat interval.
[WS => Shard 28] WS State: CLOSED
[WS => Shard 30] [CLOSE]
Event Code: 1000
Clean : false
Reason :
[WS => Shard 30] Clearing the heartbeat interval.
[WS => Shard 30] WS State: CLOSED
[WS => Shard 18] [CLOSE]
Event Code: 1000
Clean : false
Reason :
[WS => Shard 22] Clearing the heartbeat interval.
[WS => Shard 22] WS State: CLOSED
[WS => Shard 17] [CONNECTED] Took 359ms
[WS => Shard 17] Clearing the HELLO timeout.
[WS => Shard 17] Setting a heartbeat interval for 41250ms.
[WS => Shard 17] [RESUME] Session f7296839c553980131d684ff0bdde3a5, sequence 1446
[WS => Shard 17] Tried to send packet '{"op":6,"d":{"token":"NzXndXIUssnXij36A3OTgxODQ2AjPx.X_bEg.51QMzR2OF41NARLksUYYd6G4GpyoWk","session_id":"f7296839c553986784340131d684ff0bdde3a5","seq":1425}}' but no WebSocket is available!
[WS => Shard 17] [DESTROY]
Close Code : 4000
Reset : false
Emit DESTROYED: true
[WS => Shard 17] Clearing the heartbeat interval.
[WS => Shard 17] Shard was destroyed but no WebSocket connection was present! Reconnecting...
My bot is online but not responding to commands and I get these weird messages in client.on('debug') event. Token is already reset stop reminding me.
dont just spam it please
is that token has been invalidated?
yea
I'm getting something similar after pushing an update to my bot and restarting.
Token was fine (and I've reset it just incase) but shards are now starting then dying with an error stating that it failed to connect to gateway followed by session being invalid
[WS => Shard 1] Setting a HELLO timeout for 20s. [WS => Shard 1] [CONNECTED] Took 137ms [WS => Shard 1] Clearing the HELLO timeout. [WS => Shard 1] Setting a heartbeat interval for 41250ms. [WS => Shard 1] [IDENTIFY] Shard 1/75 with intents: 5009 [WS => Shard 2] [READY] Session 571e8008b0f1c08b43d0054cff39c286. [WS => Shard 2] [ReadyHeartbeat] Sending a heartbeat. [WS => Shard 2] Heartbeat acknowledged, latency of 303ms. [WS => Shard 1] [INVALID SESSION] Resumable: false. Shard ID:1 - Reconnecting [WS => Shard 1] Failed to connect to the gateway, requeueing... [WS => Manager] Shard Queue Size: 1; continuing in 5 seconds... [WS => Shard 2] Shard received all its guilds. Marking as fully ready. Shard ID:2 - Online Shard ID:2 - 0 unavaialable guilds Shard ID:3 - Launched Shard ID:2 - logged in Shard ID:3 - DB Connector Loaded Shard ID:3 - Started refreshing application (/) commands. Provided token: NDA5ODIyODMyMjU2ODc2NTQ1.Wnd7QQ.*************************** Preparing to connect to the gateway... [WS => Manager] Fetched Gateway Information URL: wss://gateway.discord.gg Recommended Shards: 53 [WS => Manager] Session Limit Information Total: 1000 Remaining: 878 [WS => Manager] Spawning shards: 3 [WS => Shard 3] [CONNECT] Gateway : wss://gateway.discord.gg/ Version : 9 Encoding : json Compression: none
This appeared to be an issue with unavailable guilds.
Adding waitGuildTimeout:1000 in front of my intents appears to of fixed the issue
@terse cairn ask here
Okie
There are two options, internal or traditional sharding
Internal
internal is easier, traditional is needed once your bots gets too big
Oh nice
@nimble mist how to use internal one?
internal sharding is done automatically by djs as soon as you specify shards: 'auto' in your ClientOptions (or a number higher than 1)
Like 2?
That is a number higher than 1, yes…
up to 2.5k guilds per shard is possible
You went full traditional sharding suddenly
Can we talk to dm?
No
@nimble mist I have created this
Yeah, that’s the code from the guide
Yeah so what now?
@nimble mist now how to show shard count in stats command?
Documentation suggestion for @terse cairn:
ShardClientUtil#count
Total number of shards
Oh ok thanks
client.shard is a ShardClientUtil
Alright
@nimble mist discord.js 12v is good for 2022?
I’m using that in my bot currently
djs v12 isn’t good for a long time now
Quick question as I'm looking into sharding my bot soon
I understand I can shard manually by creating individual instances and providing certain client options, but I'm a little confused from looking the clientoptions docs
shardCount should be the total number of shards right? So imagine I have 10 shards in total, that should be 10?
Where does the ID of that current shard go? What parameter is that? Is it shards?
https://discord.js.org/#/docs/discord.js/stable/typedef/ClientOptions
So my first shard would be
shardCount: 10
shards: 0
And then the 3rd shard would be
shardCount: 10
shards: 2
And the final 10th shard would be
shardCount: 10
shards: 9
Right?
/home/newbot/node_modules/discord.js/src/sharding/ShardClientUtil.js:35
process.send({ _ready: true });
^
TypeError: process.send is not a function
at Client.<anonymous> (/home/newbot/node_modules/discord.js/src/sharding/ShardClientUtil.js:35:17)
at Client.emit (node:events:539:35)
at WebSocketManager.triggerClientReady (/home/newbot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:17)
at WebSocketManager.checkShardsReady (/home/newbot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:367:10)
at WebSocketShard.<anonymous> (/home/newbot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:189:14)
at WebSocketShard.emit (node:events:527:28)
at WebSocketShard.checkReady (/home/newbot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:475:12)
at WebSocketShard.onPacket (/home/newbot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:447:16)
at WebSocketShard.onMessage (/home/newbot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/home/newbot/node_modules/ws/lib/event-target.js:199:18)
import { ShardingManager } from 'discord.js';
import config from "./utils/config";
import logger from './utils/logger';
const manager = new ShardingManager('./index.js', { token: config.token });
manager.on('shardCreate', shard => logger.manager.info(`Launched shard ${shard.id}`));
manager.spawn();
import './consolecommands';
Help I need to always restart my discord bot and why
It stops working on certain shards
How to detect a shard crash? I don't know why some shards stop working
After like 1 day
@serene shell this may be your issue not 100% sure tho
How do I fix this?
I mean there are no errors in console so idk
idk then if its that issue it should show that but just not resume the session
Nothing in console
you do have the debug event on tho right?
No
If that was the issue how would I fix
What I did is just install d.js using that pr or wait until they merge it and fix in v13.7
might not be the best idea tho because v13.7 is not out yet and it would install the progress on that as well
best thing would be to find out first if thats really the issue you have and listen to the debug event for example and see if a shard disconnects bc of zombie connection
How come same guild are in two shards
Both are same guild
Seems like you fetched it
Huh? fetched what
client.guilds.fetch("id")
Do you see .fetch anywhere in the screenshot
Maybe you fetched it before
No I didn't and fetching has nothing to do with this
It's just a cache of a shard. If a shard used a guild it will be in the cache.
I see
so when I have sharding I can't use guilds.fetch ?
Because that's adding servers in cache
And making the unavailable guild number more
You can filter them.
const { ShardClientUtil } = require('discord.js');
const count = client.guilds.cache.filter((guild) => client.shard.ids.includes(ShardClientUtil.shardIdForGuildId(guild.id, client.shard.count))).size;
ohk thnx
when is it good to get shards on the bot?
discord recommends it once you reach 2500 servers iirc
Ok ty
I have linked the issue and pr(fix) on that message
i think they meant this https://github.com/discordjs/discord.js/pull/7581
so we cant do anything about it yet?
yup
great people think its my fault that my bot doesnt work on some shards
Well, you could checkout the PR but that’s not stable so at your own risk
Question has been answered (in a way)
where?
In the PR they linked
how would I get it?
cuz my shards keep on crashing and I dont know why and I think it might be this. they jsut stop working ranodmly
Tap on the code</> button and use that command to checkout the PR
?
So what do I do k
now gh pr checkout 7581
You‘d need to have GitHub client installed for that
its stable, Ive been using it in production for weeks now without any problem.
@serene shell just copy paste those 2 files from pr on v13 module of djs on ur machine
how
idk what to answer your "how" ive just told you what to do using the pr
download which files
just copy the files from that pr and paste it in ur node_modules/discord.js/
which fiels
the files edited in the pr
https://github.com/discordjs/discord.js/pull/7581/files
where do i download
#7581 in discordjs/discord.js by legendhimslef opened <t:1646131103:R> (approved)
fix(websocketshard): deal with zombie connection caused by 4009
📥 npm i legendhimslef/discord.js#v13
Do you even know coding? 😂
You are asking how can I copy like seriously
Im asking where the download is im not familiar with github commits sorry.
and i cant just straight up copy cuz of this
just install it, npm i legendhimslef/discord.js#v13
This is starting to get off topic, go to #useful-servers for more info
is it discord.js v13 beta? cuz i need that due to the vc text update.
it just install other user pr. not main repo
afaik you still cant use vc text update, they just patch bot crash rn (dont know if its merged yet)
Why guilds.fetch makes a cache in wrong shard, can't it create the cache in the shard in which guild is present. Like if I use guilds.fetch in Shard ID: 2 and the guild is in Shard ID: 0 another cache is created in Shard ID: 2 and that increases the number of unavailable guilds
You can disable caching when fetching.
const guild = await client.guilds.fetch({ cache: false });
Will that help because I did that but it still cached
And I am fetching a server not multiple
I did that and it got in all shards
It should be client.guilds.fetch({ guild: 'id', cache: false })
GuildManager#fetch()
Obtains one or multiple guilds from Discord, or the guild cache if it's already available.
Ohk my bad
is it possible to launch different shards on cloudflare workers or similar?
It is, do you want traditional or internal shards? Either provide shardList to ShardingManagerOptions or shards to ClientOptions (and the respective count to let them know how many shards in total exist)
what's the difference, starting multiple applications and having a shard manager do it itself?
Traditional is having a sharding manager start multiple childprocesses/workers, while internal uses one process but several websocket instances in it.
interesting, I didn't know the difference, will have to look at it thanks!
can the ShardingManager create clusters across cpu cores?
Since it spawns child processes they should get spread across all cpu cores, unless the OS is really bad at its job
is it possible to shard across multiple machines?
^please ping me
yes, specify shardlist
module.exports = new Discord.Client({
shards: [0, 1]
// ..
});
like this?
ex. totalshards is 4, so first machine will have shardList: [0,1] and second will have shardList: [2,3]
idrk anything about internal sharding and ill suggest you to use traditional
where do i have to define shardlist tho? ShardingManager options or?
yeah
oh, i don't get that in vsc
shards have to run in order right?
wdym?
nvm, i got another question
let's say we have got machine1 and machine2
can machine1 use shardList: [0, 2, 4] and machine2 use shardList: [1, 3, 5]
sure ig
Just don’t forget to specify shardCount too, so every process knows how many shards in total exist
totalShards In ShardingManager
oh, so if i use totalShards: 4 and shardList: [0, 1] the manager will know that the other 2 shards are handled by another process?
Exactly
oh, i see, alright, thank you
is there a way to pass args to the bot.js that are defined in the shard manager
Documentation suggestion for @tired briar:
ShardingManagerOptions
The options to spawn shards with for a [ShardingManager](<https://discord.js.org/#/docs/discord.js/stable/class/ShardingManager>).
How can I get the name, icon... of a channel that might be in other shard and send it in the same channel that i used the command in
Fetch it
client.channels.fetch("id")
try {
let channel = await client.channels.fetch("847901485740457994");
if(channel) {
console.log(channel)
//...``` no err nothing @hybrid iron
it will be undefined if it's on other shard
TypeError: Discord.MessageEmbed is not a constructo
client.shard.broadcastEval(async (c, { Discord }) => {
const channel = c.channels.cache.get("807703389294166087");
if (channel) {
let embed = new Discord.MessageEmbed()
// ...
}
}, { context: { Discord: Discord } })```
read the latest pinned message
despite being outdated, the concept is still true (it applies to the context as well)

let channel = client.channels.cache.get(ID);
if (channel) {
let user = await client.users.fetch(vote.user);
user.send("HI").then(()=>channel.send(`sent to ${user}`)
}
``` is this will work?
if channel's shard is not the same as user's shard, is there a good way to do it
Pass the userID and content of message you want to send in DM as context to broadcastEval with shard:0 in options (DMs are always on shard 0). pass the channelId and User.toString() (or what exactly the string is you want to sent in reality) as context to another broadcastEval and send to channel there
client.shard.fetchClientValues("ws.status") for example
Yes, because it’s a Promise. Like all fetch methods are
Resolve the promise
Tag suggestion for @terse cairn:
Resources to understand Promise:
• MDN: learn more
• Guide: learn more
• JavaScript info: learn more
But honestly: how can you run a sharded bot but not know about Promises?
I‘m more asking how it comes that your bot is so big that it needs sharding yet you don’t know JS fundamentals that are used in about 80% of d.js code
Many cases.
The bot can grow really quick and he really has a good bot idea and didn't get time to fully learn JS and now he needs sharding. (Although, it's rare that happens.)
The messages I responded to were deleted, so I look like I‘ve been talking to myself a lot🤦♂️
how can I pass node arg to the shard?
my bot is crashing due to low heap I want to add --max_old_space_size=4096
use the execArgv option on the ShardingManager
and what is shardargs?
also debug event is not firing. Im trying to debug this but its not firing
switching to execArgv='--max_old_space_size=4096' my bot wont launch
I get the timeout as shows in the screenshot above 😦
actually whenever I set my execArgv, hwne starting the bot it enters nodejs
okay never mind. docs are wrong..type is string array not string
Hi everyone, I have a question. The docs / guides for creating commands shows a script called 'deploy-commands.js'. however, this script assumes your bot isn't sharded.
My question: I am using the ShardingManager Kurasuta, how am I expected to deploy commands to a sharded bot? Do I take the bot offline and online? Or can the ShardingManager manager find every guild for me so that I can deploy the commands by GuildId as shown below:
const { SlashCommandBuilder } = require('@discordjs/builders');
const { REST } = require('@discordjs/rest'); const { Routes } = require('discord-api-types/v9');
const { clientId, guildId, token } = require('./config.json');
const commands = [ new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!'), new SlashCommandBuilder().setName('server').setDescription('Replies with server info!'), new SlashCommandBuilder().setName('user').setDescription('Replies with user info!'), ] .map(command => command.toJSON());
const rest = new REST({ version: '9' }).setToken(token);
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands }) .then(() => console.log('Successfully registered application commands.')) .catch(console.error);
As you can see the example script assumes you know the guildId, I need to find a way of using the kurasuta ShardingManager to collect every guildId so that I can deploy my commands without taking the bot offline
this is djs help, not kurasuta
Kurasuta is just a thin layer over ShardingManager
Ok just ignore Kurasuta then, how would I go about this if it was ShardingManager?
const cmds = [
["ping", "..." ],
["server", "..." ],
["user", "..." ]
]
const commands = cmds.map((it, index) => {
return new SlashCommandBuilder().setName(cmds[index][0]).setDescription(cmds[index][1])
})``` I like to optimize everything, if you want also, take my code
Yeah thank you the optimization is nice but my issue is that I need to understand how you get every guildId from a sharded bot using ShardingManager
until I realized what you meant
The code i posted was just what i found on the discord.js guide on deploying commands
If you have a sharded bot you shouldn’t deploy guild commands but instead deploy globally.
ooh I see
that makes sense so, I got confused how the documentation suggested deploying by guild, Routes.applicationGuildCommands(clientId, guildId)
The guide suggests both methods afaik
I don't see it, could you specify how you deploy globally? I'll keep scanning the page: https://discordjs.guide/creating-your-bot/creating-commands.html#registering-commands
Suggestion for @warped idol:
Interactions: Registering slash commands - Global commands
read more
thank you ❤️
this completely solves my problem, much appreciated
Shards should be auto-respawning when they die right? I have situations where like 1 shard randomly dies, the bot shows offline for people in those shards and my fetchClientValue calls don't return. I have to restart the whole bot to get it to work again.
I'm adding some additional logging to see what's going on but have to wait for it to happen again.
Shard 0's Client took to long to become ready. at Timeout.setTimeout [as _onTimeout] (/node_modules/discord.js/src/sharding/Shard.js:89:31) at ontimeout (timers.js:498:11) at tryOnTimeout (timers.js:323:5) at Timer.listOnTimeout (timers.js:290:5)
Why I sometimes receive this error and how can I fix 🥲
Probably because you have a lot of DMChannels (or other stuff) that get cached on shard 0. you can extend the timeout duration in the spawn options of your ShardingManager if that’s the case
#7581 in discordjs/discord.js by legendhimslef opened <t:1646131103:R> (approved)
fix(websocketshard): deal with zombie connection caused by 4009
📥 npm i legendhimslef/discord.js#v13
Could it be that?👆
oh tks
Could that be it?👆
sorry, wrong ping…
hey how can i fix this err?
Scroll slightly up
👆
i see it how can i fix it?
Also in that message, last sentence
by the way dont shard on replit
Don’t host anything you want to have taken serious on repl.it would be my suggestion
Same to me
I have change the timeout duration but it didn't change
Where do you host your bot? repl.it or a real host?
On repl.it
That’s not gonna work with a sharded bot. Get a real hoster
*cause it the last one allow me to host free with
Well, if your bot is so big it needs sharding you won’t be able to get it hosted for free anywhere
Look at #resources for some affordable Hosters
Oh, thanks for suggestions
client.on('ready', async () => {
try {
let qu = await vC.find({});
const player = createAudioPlayer();
let resource = createAudioResource(something);
////////////////////
for (let i in qu) {
let roomid = qu[i].roomID;
let room = client.channels.cache.get(roomid);
// if (!room) continue;
if (room) {
let connection = joinVoiceChannel({
channelId: room.id,
guildId: room.guild.id,
adapterCreator: room.guild.voiceAdapterCreator,
});
connection.subscribe(player);
player.play(resource);
}
}
player.play(resource);
player.on(AudioPlayerStatus.Idle, async () => {
let resource = createAudioResource(...);
player.play(resource);
});
} catch (er) {
console.log("catchQur24Er " + er)
}
});```
How can i put everyting inside `if(room) {here}`
Or is it ok to keep it like this while Sharding?
Add a check if client.guilds.cache.has(room.guild.id) to make sure that room is on your shard

but room will be undefined out of the for loop
Then put the check inside the for loop🤷♂️ basically chain it to the if(room && …
Im doing it
But there are things i want them out the for loop like
Player.play()
Because i don’t want many player, I want only 1 player
Well, you will have to have 1 player per shard anyway 🤷♂️
player.on(AudioPlayerStatus.Idle, async () => {
let resource = createAudioResource(...);
player.play(resource);
});
What about this, do i need to check for room
No, because the player will only be subscribed to on the channels that exist in that shard anyway
Why does discord api block my ip after all of my shards have been spawned?
like it works before the last one is spawned and then it gets blocked
Maybe you hit a ratelimit by logging in too fast? Try setting a higher delay in spawn function…
I don't think its logging too fast
Where do you host your bot?
hetzner
it started after i switched to v13
So dedicated IP?
but the spawn delay doesn't even do anything it still spawns right after the next is ready
yes dedicated
How high did you try to set the delay? manager.spawn({delay: 10000}) ?
doesn't matter how much i set it still always spawns right after
Doesn’t answer my question what you tried but okay
ye i have tried 10 second delay to 1 minute delay and still
but this started to happen after i switched to v13
??
My guess would be there’s some oversight where you didn’t fully update your code to v13 somehow but that’s full speculation without any code
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./main.js', { token: settings.token, totalShards: 'auto', delay: 15000 });
manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
manager.spawn();
The delay literally goes in the spawn functions options. Not the constructor
welp, but that still doesn't explain why it breaks now right after i have updated to v13
Probably because you had something in v12 that slowed the becoming ready which isn’t there anymore in v13 (could be due to less caching and fetching at the start for example)
Ye maybe. I tried now with the delay, thanks
Doesn't explain the issue, the delay is hardcoded, it waits with the provided time, even if the cluster has been spawned.
Just curious, is there a list of status codes for client.ws.status? Seems 0 is online, and 3 is offline or waiting, but I can't seem to find an actual key or list of what each means
Nevermind, just had to do a bit more digging
In case anyone comes across this in a search: https://discord.js.org/#/docs/main/stable/typedef/Status
What do you mean by hardcoded? The ShardingManager spawns a shard and awaits the combination of the shard getting ready and the delay being over. So if the shard needs longer to get ready than the delay the next shard won’t get spawned as fast…
no? the delay spawns despite shards being ready or not
for (const shardId of this.shardList) {
const promises = [];
const shard = this.createShard(shardId);
promises.push(shard.spawn(timeout));
if (delay > 0 && this.shards.size !== this.shardList.length) promises.push(sleep(delay));
await Promise.all(promises); // eslint-disable-line no-await-in-loop
}
The next shard only gets spawned once the spawn and the delay promise resolve
promise.all executes all promises at the same time
Yes, and it waits for all of them to be resolved before resolving itself
i know
now you've just argued with urself
actually
createShard doesnt wait for the shard to become ready iirc
it just creates a child process or a worker
I‘m not gonna argue with you any further, read the sourcecode of Shard.js instead of guessing how it works
createShard doesn‘t indeed, but shard.spawn does
Help why do my shards keep on doing this
do u use zombie connection fix pr?
No I couldn't figure it out
So it's 100% that?
why you still dont try to use
How do I use it lol
...
npm i legendhimslef/discord.js#v13
Is this v13 beta?
As I need v13 beta cuz if not people press buttons my bot already sent in vc text channels and my bot crashes
why dont try and see?
Is it v13 beta
bruh
As Jen is here for the phones so if I do it now and it breaks my Bot then I have to wait till I'm home
just try, if it broke just switch to stable ver. i dont know if its already have tiv fix or not. im not gonna see all commit tho
I cant switch to stable I need to use the dev version as in stable buttons crash the bot if used in vc channels and people are pressing the buttons my bot already sent in vc channels
I need to use v13 beta or dev or whatver u call iit
are you on v13 or v14
v13 beta, which i need to be on
i cant be on v13 stable
so im techically on 13.7.0 beta
that pr based on v13 beta
so its on basically 13.7.0?
so try and see. as i see the tiv fix was merged 26 days ago. this pr active was 13 day ago. i think it should includes tiv fix
ok cant rn cuz as I said jen came for the phones xd
npm i legendhimslef/discord.js#v13
And I'm running this
Same, did you find a fix for this?
Installing it is broken
I used npm i legendhimslef/discord.js#v13 but it errored
I Never suggested installing it
then how should I fix it
Thats erros
I copied and edited the files with the committed code
hopefully my shards dont go randomly offline now.
I'm curious to know how discord generates worker and process id https://discord.com/developers/docs/reference#snowflakes
and how they are unique with multiple servers
it wont go offline if the issue was zombie connection. Been running fine for weeks now, 26k server bot. dm me or ping me if you need any help with the pr or zombie connection
The same way you can cluster your shards. Each server is assigned a starting point from which on they numerate their processes. Discord defines an upper limit of processes per server and makes sure the range is big enough to fit them all🤷♂️ workers don’t need to be handled separately, as each process is only on one server, so workerIDs only need to be unique in each process
thank you!
What things can cause the Sharding are still being spawned? (mention pls)
i'll do this for example to send a message
let data = "cId";
let channel = client.channels.cache.get(data);
if (channel){
channel.send("G");
// ..
}
but if then I deleted the channel while the bot offline
how can i know the channel is not on any shard, deleted, not available
In cases where you need to be absolutely sure (and catching the error if it got deleted isn’t an option) you should force fetch the channel to make sure.
is there any option for running specific file on a group of shard
like i want a index.js running on shard #1
and index2.js running on shard #2
like this?
let guild;
try {
guild = await client.channels.fetch()
} catch (er) {
// delete the room from data
}```
Well it's still going offline on some shards 😭
You won’t ever get an error on channels.fetch() without providing an ID. Also you need to pass the force parameter, else fetch will just use the cache if available
yes of course I’ll pass an id fetch(id)
what’s force parameter
if it’s available in the cache, then it’s fine i think. I don’t care if it will fetch or cache, what i want to catch if it can’t reach that room for any reason
Or I’m wrong?
show me the debug logs
how?
It's an event
<Client>.on("debug", function(info){ console.log(debug -> ${info})});
If you can catch the error then simply do so, yes
let all = await hsnM.find({});
for (let i in all) {
if (all[i].roomID) {
let data = all[i].roomID;
let time = all[i].time;
let sId = all[i].serverID;
// let room = client.channels.cache.get(data);
if (Date.now() > time) {
let room;
try {
room = await client.channels.fetch(data);
} catch (er) {
hsnM.findOneAndRemove({ serverID: data }, (error, del) => {
if (error) { console.log(error) }
else {
console.log(`❌ HHSSNN del ${sId}`)
}
})
// ...
}```
I'm doing like this, and the channel is deleted
it will log many times, but the channel will not be really removed from DB
@nimble mist
thats more like an issue with mongoose, and not djs tho?
i think it's with sharding, because i tried it without shard and it works fine
still not an issue with djs.
mongoose has no relation to djs.
no they're brothers
wdym dude?
djs is literally a wrapper and mongoose is literally a package to handle mongoose operations
Hi I can't connect my account GIthub To heroku this is my error
this is not heroku support
- not discord.js related
- I figure you just created that Heroku account else you would’ve gotten about 10 mails telling you why GitHub integration is currently disabled
Oh ok i'm gonna see
Does shardCreate get emitted for a shard that's been resurrected (ie died and then recreated)?
No, but that shards spawn event will fire on that
Shard#spawn()
Forks a child process or creates a worker thread for the shard. (more...)
I see
No, not that one. The event with the same name
Yeah I found it. Thanks!
Hey! New to sharding. This might be a broad question but what are some things that could cause a shard to take too long to become ready?
Delay set too low so you get ratelimited on login calls or (most common cause) not using an actual host but something like replit instead
yeah definitely not using repl.it. know better than that lol. I'll look into the other one, thanks!
Alrighty, recently moving to v13 after a rewrite from v12 commando, we've had some issues into sharding (23k guild bot, ~23 shards). When it comes to sharding, they spawn extremely slowly, and sometimes time's out (around shard 2). Code for spawning shards is as stated, manager.spawn(manager.totalShards, 5500, -1)
.spawn() only accepts an object with options
https://img.djoh.xyz/jG4D
so for you it will be manager.spawn({ timeout: -1 })
(i ommited other options because they are the same as the default ones)
can i internal shard forever?
Theoretically yes, but I wouldn’t recommend it for really big bots.
like how many guilds?
That depends on what your bot does exactly, as that influences how much memory your bot uses per guild
Also keep in mind that internal sharding doesn't make full use of cpus, it runs on a single process
/home/container/node_modules/discord.js/src/sharding/Shard.js:163
reject(new Error('SHARDING_READY_TIMEOUT', this.id));
^
Error [SHARDING_READY_TIMEOUT]: Shard 2's Client took too long to become ready.
at Timeout.onTimeout (/home/container/node_modules/discord.js/src/sharding/Shard.js:163:16)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7)
Emitted 'error' event on Shard instance at:
at /home/container/node_modules/discord.js/src/sharding/Shard.js:392:49 {
[Symbol(code)]: 'SHARDING_READY_TIMEOUT'
}
its okay now but shards 5 aint loading
Hi I have a question, I will soon start sharding my bot. It sends a message in a specific channel on my server when a user gets a rare item. Will that channel still be seen by all shards with this :
client.channels.cache.get(`821762092943961098`).send({ embeds: [itemEmbed] })
If not, how do I get this channel?
It will not. You‘d need to broadcastEval and check in there if the channel exists in the cache, if so then send (and either build the embed in broadcastEval or pass it as JSON)
Hmmm not sure I understand, sharding is very new to me, is the broadcastEval in the docs?
Check the pins of this channel
Ok thanks :D
Shard
A self-contained shard created by the [ShardingManager](<https://discord.js.org/#/docs/discord.js/stable/class/ShardingManager>). Each one has a ChildProcess that contains an instance of the bot and its [Client](<https://discord.js.org/#/docs/discord.js/stable/class/Client>). When its child process/worker exits for any reason, the shard will spawn a new one to replace it as necessary.
you can move away from this way to send message in a specific channel and use a webhook
Suggestion for @covert silo:
Popular Topics: Webhooks
read more
Why would a discord client have more than one shard? client.shard.ids returns an array. Could it have multiple id's?
Internal sharding
could it have multiple ids
Yes, one per shard
If i am using sharding the standard way, with the ShardingManager, will it only ever have the one id?
Yes, by default
Perfect, thanks 🙂
How can I stop my shard from restarting whenever a command was used before its ready? it immediately throws unknown interaction and has to restart then
Either register your interactionCreate handler in the ready event instead of before or check for client.isReady() in the handler
doesnt work
if (!client.isReady()) return; as the first line in my event, still get unknown interaction as soon as its ready
That sounds like you get queued interactions somewhere 🤔 very weird… one thing you could (and should) do is wrap your code in a try catch (or directly chain a catch to your command calling if applicable) provided you await all interaction acknowledging methods everywhere. Else you could make a process.on('unhandledRejection' handler (but log all rejections you ignore that way to make sure you don’t get more serious errors)
still doesnt work
module.exports = {
name: 'interactionCreate',
async execute(int, client) {
try {
// ...
} catch (error) {
const ignoreErrors = [10062];
if (!ignoreErrors.includes(error.code)) console.error(error);
}
}
}
Then you don’t fulfill the …provided that … part of my answer
hmm thought i did
ill recheck, thanks
Hi im a bit concerned about this
it never used to restart like this
What do you mean? Never restarted at all or not show the ready part?
show the ready part
it destroys all connected players
it started happening yesterday
Do you have lots of DMChannel open?
nope
are you there?
best idea, thank you buddy 😄
will djs v14 support clusters?
This works with me, it’ll throw an err but won’t restart
process.on('unhandledRejection', (err) => {
console.error(`UNhandledRejection ` + err);
}); ```
You can already cluster with v13. Unless I misunderstood your question
how to shard?
Suggestion for @merry ocean:
Sharding: How does sharding work?
read more
thx
but i made the bot login after create shards. Why it still exit before the bot ready?
Because you got an unhandledRejection in your bot code that causes it to crash. Find out where that came from and fix it
i've created an unhandledException handler
to against errors
my bot eval is public
But do you actually handle them? Or just ignore them?
yes, catches all error, abort error shutdown signal and bring the bot continue to it lifespan before bot devs turn it off to patch security error or integrate features
In what way does that handle any errors? You ignore all Startup errors that way… do you log the errors or do anything else with the actual error message?
log the acutal error, and continue to keep the process on
sharding wont work - I made the bot login after create shards. Why it still exit before the bot read
Then check your log
did
did you fix this?
did you fix this? if yes, then how? i am facing this in internal sharding
The issue is fixed yet, but I don't even remember what the fix was
Sorry homie
nvm its fine
Lemme just search through some old messages and see if I can find it
@small sable that issue was on an old version though, would be easier to just upgrade to stable
already on latest stable btw which version are you talking about?
it was on v12.5.1 for me
Still running on that version now 
Alright found it;
this happens when the socket disconnects before the open event is fired; for me the fix was to simply add another check in /src/client/websocket/WebSocketShard.js at around like 270, something like if(!this.connection) return
Although if you are on latest, then I guess they didn't fix it yet, since it was a known issue on v12
If you dig a bit deeper, you'll see that the error causing the issues is
/chip/node_modules/discord.js/src/client/websocket/WebSocketShard.js:270
this.debug(`[CONNECTED] ${this.connection.url} in ${Date.now() - this.connectedAt}ms`);
^
TypeError: Cannot read property 'url' of null
at WebSocketShard.onOpen (/chip/node_modules/discord.js/src/client/websocket/WebSocketShard.js:270:47)
at WebSocket.onOpen (/chip/node_modules/ws/lib/event-target.js:144:16)
at WebSocket.emit (node:events:329:20)
at WebSocket.setSocket (/chip/node_modules/ws/lib/websocket.js:177:10)
at ClientRequest.<anonymous> (/chip/node_modules/ws/lib/websocket.js:670:15)
at ClientRequest.emit (node:events:329:20)
at TLSSocket.socketOnData (node:_http_client:556:11)
at TLSSocket.emit (node:events:329:20)
at addChunk (node:internal/streams/readable:304:12)
at readableAddChunk (node:internal/streams/readable:279:9)
at TLSSocket.Readable.push (node:internal/streams/readable:218:10)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:192:23)
thanks a lot ❤️✌🏻
I can't guarantee this works on whatever version you're on though
in which method u added it?
Rn the issue is
close emitted -> clears the interval and never reconnect. This is with 1000 event code
Also had 4009 one which I fixed. I have an issue/pr on djs for that.
Not rly sure about 1000. I am debugging in production. Hopefully I'll get to the issue.
I added the check at onOpen, this event is kinda useless anyway since it only sets a status
But this is only tested to work in v12.5.1, unless they didn't change anything here it shouldn't work in other versions
If there is no this.connection, then the socket events are already useless, what I did would simply avoid the error coming up, but its not really a fix for anything
This issue has been known for a long time, if it still exists on current stable then 💀
how so
By providing a list of shards that the ShardingManager should spawn in its options. Along with the amount of totalShards that exist
ShardingManagerOptions
The options to spawn shards with for a [ShardingManager](<https://discord.js.org/#/docs/discord.js/stable/class/ShardingManager>).
not sure if this is actually a question about sharding, but I was wondering if there is a standard way to handle updates without downtime (even though I have a single bot instance still)
basically, I have a setup where I'm autodeploying my bot, but currently there is short downtime during the deployment where the existing instance is terminated but the new one hasn't come online yet
I'd like to start the new instance first, then once its online terminate the old one. the obvious problem being that now there is a small window where two bots might handle a command. is there a straightforward way to ensure only one of my instances gets any particular command?
Discord.js attempts to avoid rate limits by queuing up API calls correct? I am running into issues hitting the global rate limit and I think it's partially due to running shards on multiple different machines, each with their own separate API queues. Discordeno solves this by have a single REST handler for all shards to use. Does discord.js have plans to add anything like this? Or do any 3rd party packages exist to handle this?
D.js has alr separated the rest module into its own package
In the future, you should be able to easily change out any module with a custom implementation or extension
Hey! Anyone know if there's a way to in the same shardingManager create a shard but with a different discord bot token?
why would you do that?!!
Because, for example mee6 have, i want to run my code in my machine qith the token of someone that buy it.
But that would need a completely different instance, not just a shard
Shards are the same bot only spread across different processes/workers. Different token is different bot
Yea
Hi, do you know how to get the number of the shard?
<Client>.shard.ids
thanks
how to use sharding manager in typescript 
compile the typescript files into javascript, and pass the built file path in the ShardingManager constructor
I received this error
seems like you're importing the ts files
hii, i want to know which better internal djs sharding with sharding manager? 
Depends. They do different things. Internal is easier to maintain, while traditional (with ShardingManager) uses more than one process and thus is able to use more than one CPU core and does better load balancing, but you need to put in some more work when you need to handle DMs or inter-guild information (like global stats, sending information from one guild to another, …)
how can I check if all shards are spawned?
should I compare <Managar>.shards.size and <Manager>.totalShards
Depends on what you want it for. shards.size will equal totalShards only if you have only one ShardingManager running on one machine. And it will be equal after calling spawn(). The Shards won‘t be ready by then though.
If you simply want to do something once all shards are spawned (and logged in) then resolution of the Promise you get from ShardingManager#spawn() gets you that
i get the error Error [SHARDING_IN_PROCESS]: Shards are still being spawned so i want to check if all shards are spawned
Then do whatever you did causing that error on resolving the promise (so await the spawn or .then it)
well, i dont know what caused that error
Don’t you have a stacktrace?
and i cant just await it since its no async function
no
@nimble mist this is the only thing i get
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
and it doesnt really help debuging
Only that one line? No further stack?
yes
Then show your sharding code
const config = require("@root/config.json");
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./src/bot/index.js', { token: config.client.token });
manager.on('shardCreate', shard => console.log(`Shard ${shard.id}: launched`));
manager.spawn();
module.exports = manager;
it worked with 2 shards, but since i have 3 shards it throws that error
Why would you ever export the manager? Importing that file anywhere else will seriously f up your sharding
because i need the manager? and why would it fck up my sharding? everything works fine
What for? You start the bot by calling the file you posted here. Each shard then has client.shard of type ShardUtil to talk with the manager. You should never import it anywhere, because then each Shard would start to shard some more
because i need to use broadcastEval also outside of the bot
Then implement another way to talk to the ShardingManager process, not start another instance of it
yea and how would I do that?
Depends on what it is that needs to talk to the manager
wym? its a file
Files don’t talk
yea thats why i asked wym
Files also can’t use a ShardingManager. NodeJS programs can for example
its the same process if you mean that
but outside of the bot
So you start the manager by requiring it somewhere else instead of calling it directly?
yes
i initially require it in my main file
Then that somewhere else obviously is the source of your error
but its also used in other files
so how would I do this?
The way you currently have it the best way would be to pass the manager from your main file to any subtiles that need it. But to give you a definite answer I‘d need to know more than it‘s something else outside of the bot
then what info do you need?
Whatever you are willing to provide. I understand if you don’t want to disclose information, but I can only work with what you provide
so the general structure is, theres a directory bots and some others, including routes which is used for an api and a dashboard
and the dashboard and api are running outside of the bot, and they use the manager to get a client object when necessary
Can you pass the manager from the main file to some function you have to start the dashboard? And same for API?
not really
i could save the manager in the express app i think, would that work?
I guess
let me try
@nimble mist nope doesnt work, since the app instance is not even used in my routes because of the router and there doesnt seem to be a way to get the app from the router
so ex-and importing looks like the only way.. is there a way to not reshard every shard but still export the manager? or do you have a different idea?
@nimble mist ?
If you must import it in different files you could wrap the spawning of the ShardingManager in a function and export that too, call the function in your main file (or simply call spawn on the imported manager directly in your main file)
so like this?
const manager = new ShardingManager('./src/bot/index.js', { token: config.client.token });
manager.on('shardCreate', shard => console.log(`Shard ${shard.id}: launched`));
const spawn = () => {
manager.spawn();
}
module.exports = {
spawn,
manager
};
Yeah, but I realized while writing my idea that you don’t need to export the spawn thing at all. Simply import the manager and do manager.spawn() in the mainfile
well spawning seems to work but when importing the manager, i get manager.broadcastEval is not a function
logging returns a right looking shardingManager though
works now, thank you very much
@nimble mist the manager import thing seems to work, but the initial issue is still occurring
after shard 0 and 1 are launched, it throws the SHARDING_IN_PROCESS error mentioned above
then continues with the other shards
and everythings normal after that
Await the spawn in your mainfile then before doing anything else
Best await it before even requiring the other files, if possible
did that but doesnt change anything
i used an IIFE function for the async if that matters
Hello, when I start my bot now it works until the second shard starts and I got an error that it took too long I set the timeout to 9999999999 but that also didn't help the bot just takes way longer I didn't get the error yet but it takes forever does someone know what the problem is? Everything worked before today tho and I changed nothing
const { ShardingManager } = require("discord.js");
require("dotenv").config();
// Create your ShardingManager instance
const manager = new ShardingManager("./main.js", {
// for ShardingManager options see:
// https://discord.js.org/#/docs/main/stable/class/ShardingManager
totalShards: "auto",
token: process.env.TOKEN
});
// Emitted when a shard is created
manager.on("shardCreate", (shard) => console.log(`Shard ${shard.id} launched`));
// Spawn your shards
manager.spawn({timeout: 9999999999})
It does matter, because then you require the other files before the spawn finishes.
so how should I do it then? i cant use await outside of it
Do you host on replit?
Nope I host on my own vps
Best way would be to have all your other stuff only start working on function call not requiring and call those after the await resolves. Less clean way would be to require inside the IIFE after the await resolves (but that might get you other issues)
Huh, because it sounds like you might be ratelimited or out of resources for spawning another process…
Should be enough memory it has 8gb ram a ratelimit could be the problem but it is weird that the first shard works
well just for now i tried the second way, and it does not change anything at all
Well, do you have a delay set for spawning? You might be spawning them too fast
The default one ig
Try setting delay higher, just for science
Very weird. Also you should try to track down where exactly that unhandledException originates, starting npm with certain parameters should help with that (the error message usually even suggests them)
yea it doesnt here, i showed you the error
it provides no help at all
i think i found out that the error comes from the sharding file, because before that await its logging and then after it its only logging again after that error and after the shards are done spawning @nimble mist
i also sometimes get Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.
That just means that the error happens while the ShardingManager is still spawning. Unless you made sure that all other code is only ever called after that await that doesn’t mean the error comes from there necessarily.
Anyway, please try listening to the debug event and log its output
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
@nimble mist output is here: https://sourceb.in/APDPLTY3Ir
Do you call fetchClientValues in your client.on('ready' event?
There’s your issue then. Shard 0 becomes ready, tries to ask Shard 1 and 2 but they‘re not ready yet…
so how do I fix that? I think I remember there is a websocket endpoint which indicates that all shards are ready but i cant really remember and i dont know how to use it
I remember seeing that too but couldn’t find it either now. Anyway you could probably do a broadcastEval from the ShardingManager after the spawn resolves to make the shards do what you want them to do after all shards are ready
thank you, i did that and it now works!
wut did u do
what?
i mean i have same error
what error
how to fix that i didn't understand what he said
just read what he told me if it was the same error
shard timeout | SHARDING_READY_TIMEOUT
i didn't understood
error has not always the same cause
I have a sharding manager
const manager = new ShardingManager(botFile(), {
execArgv: process.execArgv,
totalShards: "auto",
token: config.TOKEN,
mode: "process",
})
// Shard Create Listener Here
manager.spawn();
// create extra shards
And after that I want to create more special shards with the manager.createShard() method but it's always saying Error SHARDING_ALREADY_SPAWNED: Already spawned x shards any idea how to fix this
What do you mean by „you want to create more special shards“? Setting it to auto means it‘ll spawn exactly the proposed amount of shards and set the number of shards to that number. You shouldn’t create single shards from it afterwards.
My issue is that I want for example 3 shards running with token A and then I want a 4th shard running with token B. So my idea was: Manager creates the shards I need (in this example the first 3) and then I can create a 4th one and set it's env to token B
Umm, what? Two different tokens means two different bots, hence two different clients. You can’t manage those with the same ShardingManager
But the code is the same
Two bots running the same code are still two different bots
I get the feeling you don’t fully understand what shards are, they processes running the same bot with the same token, but each only serving a different subset of guilds. You can of course spawn another bot in your ShardingManager, but you‘d need to do it with new Client and providing the token to that clients login method.
Hey, how do I get the GuildMemberManager from a guild fetched from broadcastEval ?
is there any way for shard to communicate with the master process? I'm trying to store a large variable in-memory but dont want to store it on every shard...
Not possible
Values that pass through broadcastEval must be json-serializable
So i just started up a discord bot, and ive never dealt with shards before. I tried googling but i couldnt find an answer. Is it possible to manually change a guild from one shard to another?
No
How I can transfer constant from sharding file (index.js) to main bot file (bot.js) (shard manager launching bot.js)
I need to log in Steam in sharding file (index.js) and then export steam client to all shards, then on each shard I can use this steam client.
Why is the Shard constructor private in typescript? I wanted to handle the shard creation myself
You can only send JSON over, not class instances. So you might need to log into steam in every shard separately
Because shards need to be added to the ShardingManager if you want to use it. Therefore ShardingManager#create handles instantiating Shards and registers them with the managery But usually you wouldn’t even call that yourself but use the spawn method instead.
If you don’t want the Shard to be registered with the Manager you shouldn’t use the Shard class either, since they rely on each other. So I can’t really see why you‘d want to directly instantiate a Shard
I have log only one time, cant more than one time
My one shard is having a very high ping and late response time, but on other shards it's normal, what to do?
In that Case you‘d need to have the connection in the Sharding file only and send requests from the shards to it and the responses back via the inter-process communication channel
Or have it in a particular shard and do broadcastEval to that shard
Anyone?
Is it shard 0? Or another one?
I have 3 shards, 0,1 are ok, 2 is having a ping of 190k-980k
Are there still free resources on your host or are those three shards somehow take up most of it? Also list how many guilds each shard serves, might be that shard 2 is overworked (in which case making four shards could help lower your load and thus ping)
Wait see this
The pings look okay though
Websocket ping is ok, but message edit ping isn't ok for 3rd shard
@nimble mist see this
Might be ratelimited?
for what reasons?
How would I know, I don’t know your code/what your bot does. Listening to debug event and logging it would tell you more
Ohk :(
@heady isle how did you print ram usage
C:\Users\k-van\Desktop\CoffeeBOT\node_modules\discord.js\src\sharding\Shard.js:166
reject(new Error('SHARDING_READY_TIMEOUT', this.id));
^
Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.
at Timeout.onTimeout (C:\Users\k-van\Desktop\CoffeeBOT\node_modules\discord.js\src\sharding\Shard.js:166:16)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
[Symbol(code)]: 'SHARDING_READY_TIMEOUT'
}
I've been getting this error for two days, I couldn't find the solution
#rules 6. I'm also not the person to ask about sharding
Check the debug event for possible reasons (ratelimit, …). Also do you have lots of DM usage in your bot? Since those all get handled by shard 0… if all that doesn’t give you a reason it might be an idea to simply raise the timeout limit in the ShardingManager
no dm usage in bot
how do i make timeout
Documentation suggestion for @terse cairn:
ShardingManagerOptions
The options to spawn shards with for a [ShardingManager](<https://discord.js.org/#/docs/discord.js/stable/class/ShardingManager>).
Because there is no event named shardCreator. It’s shardCreate
Then??
How to make like this??? @nimble mist
Sharding: Getting started
read more
By writing what that video shows instead of wrong stuff. I even told you exactly what you spelled wrong and how it‘s right. If you‘re not able to understand that then I can’t help you.
I understand!
I understand , but I think here is a fault!
Documentation suggestion for @unkempt goblet:
ShardingManager#spawn()
Spawns multiple shards.
do not use replit, sharding and replit are almost incompatible
the first error comes because replit is trash and it cant load the shards on time, you can set time out (you can see how to do it on the sharding guide) in order to avoid it
the second error comes because you have used a web port in the same time, which is incompatible with replit, you can avoid it by setting your web server port to 0
but again, sharding on replit will cause you a lot of problems and you will need to move to another platform
- that to host a bot on replit is not a good idea
so I advise you to not host your bot on replit @unkempt goblet
Then , which platform is best for hosting?? Vs studio?
Use a vps
Hey guys, stupid question:
I was wrapping my head around having the bot deploying in a kubernetes cluster with multiples (n) nodes but that will spawn n processes and connections, I guess this is what sharding is for? Or there's a specific way to handle this usecase
You could do it with kubernetes (complete overkill unless you have like 100k+ guilds) or use the sharding manager provided by djs (or one made by someone else, like Kurasuta)
How to get websocket ping for shards
Please ping while replying.
Gitpod ||not sure||
hosting and writing code are 2 different things. vs doesn't host anything
client.shard.fetchClientValues('ws.ping')
Thanks
Is there a way on Internal Sharding to know when a shard starts?
i tried evaling it, first bot on d.js v12 and 2nd 13 stable
Okey! Thanks u.
You can check the status of each websocket shard
What's Wrong
The token you provided isn’t string
Done i fixed
But Why in Code stats I added its Undefined
How i can define the shard
Wdym?
I mean i need to see how many shards in bot in code stats
client.shard.count (when using ShardingManager)
Oh thank you very much
Thats was i needed
i do have both debug and warn
He meant IDE i guess
am getting this all day
You have to wait a little over 5.5 more hours
oof
It tells you in the error
Will attempt another connection in ${time}ms
💀
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./bot.js', {
totalShards: 2,
token: process.env.token
});
manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
manager.on("disconnect", async (shard) => {
console.log(`[${new Date().toString().split(" ", 5).join(" ")}] Disconnected Shard #${shard.id}`)
})
manager.on("death", async (shard) => {
// shards.spawn(shards.totalShards , 10000);
console.log(`[${new Date().toString().split(" ", 5).join(" ")}] Killed Shard #${shard.id}`)
})
manager.spawn({ timeout: -1 })
.catch(console.error); ``` @nimble mist
Do you require your ShardingManager (the file containing the code you posted) anywhere in your code?
No
I did it before and it’s wrong i know
Do you fork any other ChildProcesses for other stuff unrelated to sharding?
I don’t know even how to do that 🙂
Then show your client ready event in bot.js (or any subfile you include from there
Idk what do u want to see exactly. should i send the way i play audio’s in ready event
I want to see whatever you do in your ready event handler. If you play audio directly in that event handler then it would be part of it, yes. But please paste the code in a bin, not directly here
Ok
I just wanted to ask for bin link
https://sourceb.in/skEbOmjrBy @nimble mist
I did play twice 
But i don’t think this is the reason
Does your bot do anything else fancy?
You don’t play twice. You play as often as qu has items and one more…
So I’ve to remove that one inside forloop
It wouldn’t cause your error though, because player just returns if you try the same resource it already plays
Do you get the same error when you don‘t shard (the event listener one)?
Before sharding.
Sometimes it disconnect, but i don’t get that warn
It was on replit that time
Try to run your bot without sharding now (simply call bot.js directly and comment out any cross-shard communication you might have) and find out if the warn emits or not. If it doesn’t stay here and tell me, if it does anyway we‘ll continue the search for reasons in #archive-voice
If i did this (bot.js) it will work in all servers?
If you don’t tell your Client constructor in bot.js to explicitly not work in every server, then yes
i did node bot.js but it says i have to shard
Show your client constructor then, put a shards:'auto' in there in case you don’t have it
do u mean this👀 js const { Client, Intents } = require('discord.js'); const client = new Client({ intents: [ Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS, Intents.FLAGS.GUILD_INTEGRATIONS, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.DIRECT_MESSAGES ] });
const client = new Client({
shards: 'auto',
intents: [```
@nimble mist it’s working until now.
that warn emits after a while, so how can i know that this will work?
And if it works, this mean the issue from where?
🥲🥲