#archive-sharding
12465 messages · Page 1 of 13
no
maybe if you expect your bot to grow extremely fast.
but I wouldnt look into it until 1k servers, and if you go over 2k you can buy some time with internal sharding
It really doesn't matter, you're just gonna run with one shard, which is essentially the same as not sharding, you can do what you want really
Do I need to edit my whole code to shard?
My bot is reaching 2.5k+ soon
we have some general information here (and following chapters): https://discordjs.guide/sharding/
the gist is that instead of starting but a single client you start a sharding file, which orchestrates multiple interlinked clients to be instantiated instead
any code that needs to interact with multiple guilds (global counts etc.) will need to retrieve and accumulate that information from the various shards, though (see the broadcast eval section)
Official resource: https://discordjs.guide/sharding/
Unofficial resource: https://anidiots.guide/understanding/sharding
Maybe this should go in the channel topic ^
you could also use internal sharding, which requires barely any code changes, but is less scalable in the long run.
afaik you can just specify 'auto' for the ClientOptions#shards property
https://discord.js.org/#/docs/main/stable/typedef/ClientOptions
Traditional sharding with discord.js
• Guide: https://discordjs.guide/sharding/
• When do i need to shard? At 2,500 guilds
• One process per shard
• Requires communication between processes (broadcast eval is needed to execute code on all shards, if you aren't sure which shard (= process) information can be found on
Internal sharding
• In-process (hence "internal") sharding
• removes the need of inter process communication via broadcast eval calls
• If your bot grows large you might find it necessary to use process based "traditional" sharding instead
// Internally sharding automatically
const Discord = require('discord.js');
const client = new Discord.Client({ shards: 'auto' });
// Interally sharding with specific shards
const Discord = require('discord.js');
const client = new Discord.Client({ shards: [0, 1] });
Mixing both approaches
• If you need X shards per process on N processes
I run a fairly large bot (18k servers), and am currently using Traditional sharding + worker threads for the shards, so it is all essentially the same root process. I have also created "clusters" where each cluster or root process is handling 16 shards each.
However, I am running into problems with high memory usage, and was thinking about switching to internal sharding to save on memory. Would switching to internal sharding at 16 shards each root process not be recommended? I'm trying to think what downsides there could be to what I'm currently doing.
biggest difference between sharding manager and internal sharding is that sharding manager spawns separate processes that are copies of the main code, and each of them handles only part of the guilds at once.
internal sharding however only mantains multiple websocket connections, everything else runs on exactly same process, so while you can theoretically save small amounts of RAM by not having duplicated users between shards (as there is only one cache in this case), but that also comes in with the fact that all of the events are on the same event loop (normally you could not be able to get messages from more than 2500 guilds on one process, but on internal sharding you have all guilds on same process), and while that probably is not going to be a problem with bot of your size, it can probably be one later on.
only point on which you could save memory is by having single cache for users. everything else would be exactly same, since channels, guilds, members etc were completely separate between processes
I think I see, so I would be basically having more load on that single process
yes
you can mix it to have e.g. each process doing internal sharding on 5 or 10 shards
but the memory difference is probably not that big
in such case all the profit you could get that i mentioned is probably gonna be non-existent
since you again split the caches
Even with worker threads they each have separate caches?
Thank you for the help btw, this is all good to know
I did some quick tests and switching to internal sharding cut my memory usage in half, but CPU usage on 1 core tripled from ~10% to ~30%
I mean you also save yourself the overhead each nodejs process needs and stuff like that
I've been using worker thread mode, so that should share 1 node.js process I believe
Does worker thread mode automatically spread the load among CPU cores? It seems to be doing so based on what I'm seeing
Aha finally it here
same lol
how did you measure that
htop on debian... I changed my production bot temporarily lol
so you just booted the bot and that's that?
I measured both after a fresh boot, yes
ah hi wise
all my shards stopped working
.
please read the pins
How can you check if there is a bot on a specific server if shards are used?
client.guilds.cache.get("GuildID") - not working...
@rotund bridge try to read this first https://discordjs.guide/sharding/
if you use internal sharding that should work
(see pins)
I can sure you can find solution here if not I will help you with some code hint
@royal beacon I studied all the information on this, but I could not find a solution ...
Oh, snx! I try this!
with traditional sharding: have a more detailed look at broadcasteval - you don't necessarily want to get a functioning Guild structure back though, but instead do whatever you have to do inside the broadcast eval and return data, instead of structures
I never heard that we have another way to shards ? can I have more information about it
updated, can also do a hybrid of both, but need some missing information from mr. internal sharding before i add that
So it is possible to do a hybrid approach with the current library?
What is sharding?
see pins
Woa finally. So quick question, how do you restart websocket shards?
You can respawn a shard which will kill it and spawn it again.
some stupid question from me can I using both tranditional and internal sharding together ?
what does nearly mean?
on shard status
nope, you cant, but someone is working on it, to make it possible
internal sharding, client.ws.shards.get(shardid).destroy()
Sharding manager ```js
client.shard.broadcastEval(if(this.shard.ids.includes(shardid) process.exit()))
destroying restarts it?
yes, just the shard
When the shardDisconnect event is fired, is it safe to spawn another shard or should it just be left alone?
Leave it alone. shardDisconnect is fired whenever the shard disconnects due to discord asking it to or a network error. Djs will try to resume the session if the error is not fatal.
https://github.com/discordjs/discord.js/blob/ee5bc1a5c4e218ea1f16992694a2bff86c86d2d2/src/client/websocket/WebSocketShard.js#L269 Only ever referenced here. Seems to be when the connection is open by the client is not 100% ready yet
No destroying just closes the connection gracefully without restarting it.
So just for sharding, we need to add shards: "auto" in client?
for internal sharding, yes
Since client.shard.id is gone in v12, what should I do to get the shardID of the specific instance? Or should I just access the guild cache every time to get the shardID value?
isnt there client.shard.ids
it's an array of IDs right?
yeah
would it be the same value? or does one instance cover multiple shards?
I would assume that it should only contain the ids the actual client handles, but I dont use traditional sharding
I guess I'll scuff my way through and just take the first element
and yes a client can cover multiple shards, afaik
so what happens when you restart a specific shard
just log it and I would guess its only one value
Aight
I dunno, sorry I'm only familiar with the theory, I use internal sharding
Aight aight
if anyone has experience with this please explain it to my monke brain thancc
oh nvm it's an array with one element, problem solved
If you use the sharding manager client.shard.ids will be an array of 1 element that element being the shard that the client is handling.
client.shard is only available if you use the sharding manager if you use internal sharding it will return undefine
Yep I do use the manager
So that solved everything,
thanks
Anyone have a good sharding tutorial?
the pins should do
if you have extra questions try to answer them yourself or just ask here
Ok. Thanks!
@wispy verge stop shitposting.
bruh
@strange echo help please
?ban @wispy verge returned to shitpost in support
You sure you want me to ban this [no gender specified]?
y
Successfully banned Lmao#0001
I have a cuestion, how Can i sens a message to a specific channel when its on anther shard?
one sec, code is coming
let channelid = "the channelid";
let yourmessage = "";///add some thing
client.shard.broadcastEval(`this.channels.cache.has("${channelid}") ? this.channels.cache.get("${channelid}").send("${yourmessage}") : null`).then(console.log);
thx i will try it soon
Does this.users.cache.get(id) in a broadcastEval() return a Discord.js User type or just a plain object without methods like .send()?
No that is a poor implementation. Construct the channel and send it from there.
const guild = new Discord.Guild(client, { id: "1234567890" })
const channel = new Discord.TextChannel(guild, { id: "1234567890" })
channel.send(embed)```
Doesn't have any broadcast evals and is super fast. Typed on my phone so apologies for errors
It will return a discord user type
Plain object without methods
It wouldn't be of type User
When should one consider sharding?
check the pin
thx
@wet pawn @green hill that depends where are they "returning" that object out.
inside of the broadcastEval(), it will be proper User object. ```js
broadcastEval('this.users.cache.first().constructor.name')
// [ 'User', 'User', 'User' ]
taken *outside* of the `broadcastEval()` , you are not going to get proper `User` object back. ```js
broadcastEval('this.users.cache.random()').then(results => results.map(obj => obj.constructor.name))
// [ 'Object', 'Object', 'Object' ]
Thought they mentioned when it's "outside" of bEval
they didn't say anything specific to aything
so since they got two different answers now, clarified
Yep
@mild shore as well, didn't ping above
I already knew this Solution, but for a beginner, wouldnt be it better, that they check if there is a channel?
As far as I know, this will send the request directly to the gateway
Yeah sorry I assume they ment inside. Personally I do logic inside for exactly that reason. Sorry for the confusion!
Well not necessarily. I don't think that solution is any easier to understand and is far more complicated and uses more memory and CPU. If you prefer it ofc do it but constructing them is more efficient by a mile
i would very heavily suggest you don't manually instantiate channels, or any discord.js structure, for that matter. They won't work as you expect them to and you may or may not be entering invalid structures into cache which can cause all sorts of unwanted and very hard to debug behaviour further down the line
(and please don't recommend that as superior solution for the sake of efficiency.)
What I do, and maybe this is not the best option, but I extend the DJS Client class and make a CustomClient, and add extension methods for anything custom I want to do in a broadcastEval(). This way the method is being interfaced, so if the DJS implementation changes, I can still get build errors.
Extended client class:
export class CustomClient extends Client {
constructor(clientOptions: ClientOptions) {
super(clientOptions);
}
public async setPresence(type: ActivityType, name: string, url: string): Promise<Presence> {
return await this.user?.setPresence({
activity: {
type,
name,
url,
},
});
}
}
Calling extended method in broadcastEval:
await this.shardManager.broadcastEval(`
(async () => {
return await this.setPresence('${reqBody.type}', '${reqBody.name}', '${reqBody.url}');
})();
`);
This is typescript, but I'm sure the same thing can be done with JavaScript.
yeah! my solution won lol
whats the difference between internal sharding and traditional sharding?
traditional sharding spawns multiple child processes (each process taking one shard) and you have to make quite a few code changes (depends on what ur bot does)
internal sharding keeps all the shards in a single nodejs process, you barley need code changes (usually just two lines)
internal sharding is not as scalable, but depending on your bot it can take quite a lot of shards
I'm posting here as a last resort... I'm not doing anything with shards myself, but I am encountering an error that involves one.
I'm attempting to join the voice channel of the user executing a command. In this one specific server attempting to do so results in the following error (see attachment). Code is simply as follows:
connections[msg.guild.id] = await msg.member.voice.channel.join();
Why would a guild's shard be undefined?
@prisma dew not too sure why you think this is sharding related or where this points to a guild's shard. this is very likely related to the new stage channels, which aren't supported in discord.js yet.
if you are still on 12.5.1 please update to 12.5.3, we fixed some things since then to prevent hard crashes.
It's not a stage channel. I traced the callstack and it lead back to a line in the VoiceConnection class where it attempts to call send on the guild shard
why did i look at 183... good question
Error occurs on this line of VoiceConnection:
can you log client.ws.shards.keyArry() as well as the guild's <Guild>.shardID please?
I'll log the first one here momentarily
I already know that the guild's shardID is also undefined
what 
The keyArry() returns the following array: [ 0 ]
And, confirmed. msg.guild.shardID is undefined
is that a typo
Is what a typo....
keyArray
It was, my intellisense autocompleted to keyArray()
yes, it is, but they found it - so irrelevant
Guild#shardID should very definitely not be undefined, ever
I figured not. Guild is not undefined, but the shard, and the shardID are
@prisma dew which exact version of discord.js are you on, before i do a deep dive into the code base? npm list discord.js
12.5.3
Ah alright. Thanks! 👍
@acoustic epoch previously I was on 12.5.1, due to your suggestion I updated and tried all the same tests again, with the same results
yeah, we didn't change anything in that area, 12.5.1 -> 12.5.3 was just stage related things
I'm having some issues with fetching a user across all shards and sending them a DM, getting an error that .send is not a valid method. Am I not getting a type User back?
const fetchUser = async (message, id) => {
const user = await message.client.shard.broadcastEval(
`this.users.cache.filter(user => user.id === "${id}")`
);
console.log(user); // logs a user object
return user[0];
};
no, broadcastEval returns an array of data results from each shard the eval was executed on.
the returned structures (array) won't be functioning User instances either, but a JSON-sendable version of them (no methods, just the data)
you should do these things in the eval itself, rather than trying to retrieve the user to the outside scope
the base idea is to just return simple data from the b-eval calls and doing things with the structure inside the eval, so it gets executed on the shard directly
literally just after you mentioned me with explanation
Ohh alright, thanks will try that!
@prisma dew msg.client.shard is undefined too?
and do you use any client options in the client constructor?
Let me check...
Nothing passed to the client constructor
msg.client.shard appears to be (specifically) null
Oh really? It seems so much cleaner and I've never had any issues with it. It obviously is way more efficient than fetching the correct channel just to get access to the .send method. What is the reccomended way? ( For the record I don't know how I could be entering invalid data is I just construct the channel with an ID )
whats of shard's benefits?
const { ShardingManager } = require('discord.js');
const Manager = new ShardingManager('./bot.js', { token: 'your-token' });
Manager.spawn();
https://discord.js.org/#/docs/main/stable/class/ShardingManager
For an in-depth guide: https://discordjs.guide/sharding/
sharding splits the load between different processes, and is enforced by discord when you reach 2500 guilds
is it good thing or ?
well, considering it's enforced, yes?
there's no point in sharding before 2000 guilds though
Any one knows how to get total servers in all shards using const
Or
console.log(`SERVERS: ${idk how}`)```
Fairly sure that this is explained in the guide
You can use fetchClientValues(), there is an example in the guide here:
https://discordjs.guide/sharding/#fetchclientvalues
@acoustic epoch sorry for pinging you, but were you able to get any more insight into what may have been going on?
only update i have is that someone else ran into it as well, so it's definitely a thing, no idea what causes a guild to not have a shard yet
I see. Thanks for your help nonetheless
Could someone please explain this btw? ^
why it didnt work ?
What are you even trying to do
Cause that looks like a wrong way
I don't see what more you want explained. Souji went into full detail explaining why instantiating djs structures is not something you should do.
I mean I guess I don't believe him. I've looked pretty thoroughly at the code for channel constructors and u don't see how what he says could happen could happen? By providing just and ID you're not entering data and it twill still have all the same methods as a normal channel? I can't understand why there is a downside to it?
Because you're passing invalid guild data to the constructor? If you don't know how to properly construct a guild e.g. to mock it in unit testing, there is no reason to use the internal constructors as you will just add invalid structures to the cache as Souji already said.
So I understand how there could be I valid data but if the structure already exists in cache it won't get overridden? How is it suggested to send a message to a different channel with sharding?
Anyone help me in making shards status like servers, users etc.
use fetchClientValues and broadcaats eval
How can I get a specific variable from a particular shard, for example get the number of connections to vc from shard 1?
why is this happening when I start my shards? (D.js version 12.5.3)
client.shard.broadcastEval(`if(this.shard.ids.includes("${shardid}")) getvcconnections()`)
That's because that guild have an stage channel
Well how do I suppress them?
those are really annoying lol
Hmm, dont the latest version fix those? I thought it did
Hasnt, they spam all the way along
i made from tutorial and it returns null
did you updated your package?
^
After the update, the spam increased.
show me the code
kk
// For each shard, get the shard ID and the number of guilds it owns
let values = await client.shard.broadcastEval(`
[
this.shard.id,
this.guilds.size
]
`);
// Make a final string which will be sent in the channel
let finalString = "**SHARD STATUS**\n\n";
// For each shard data
values.forEach((value) => {
// Add the shard infos to the final string
finalString += "• SHARD #"+value[0]+" | ServerCount: "+value[1]+"\n";
});
// Send the final string in the channel
message.channel.send(finalString);
are they different guilds?
Well the shard that holds that one guild is offline meanwhile the shard that holds the other one isn't
@mild shore do it in broadcastEval, by getting the channel. One of the shards has it
How would you implement a command to send to all guilds? Seems super heavy weight when really all you are doing is sending a message?
You just grab the guild/channel and send the message as tip said above?
So if I sent to 20k channels I have to broadcast eval 20k times?!?!?!
No
I've never had a problem with just constructing the channel and the only alternative methods I can think of all require super hacky ( and useless ) ways of doing things? One alternative is just to send a straight request?
You could let Discord do all this work by using a news channel.
Needs to be custom messages + mentioning
space's point still stands
How? he didn't even make a point? News channels won't work for my use case
What is your use case?
You could just be less obnoxious. We're trying to help you.
Didn't mean to be obnoxious apologies just don't understand why mu current method is incorrect. My use is alerting users when a virtual item hits a certain price. Messages need to mention custom roles + have custom currencies
Nothing stops you from having a central guild that has channels for that. If someone is interested, they will most likely join that guild
So I did think about having 1 news channel for each currency but I have like 30 odd different currencies so each requires a separate channel. Is an option though but still doesn't solve the mentioning problem
People really like @ here and custom roles for certain mentions
Wish discord would support mention propagation insdead of having @craggy bluff-role ( sorry for ping whoops ) even still doesn't support custom roles for channels
I'm not sure why you wouldn't keep your pre-sharding approach.
Explain sorry?
Just send to all appropriate channels available on the current client, do this on all shards and you got all channels covered. No broadcasting necessary.
Well I did think of that option but it fucks rate limits. Sometimes if things break I can get destroyed by the rate limits and if I have each shard sending the messages it gets fucked over even more
Oh, the global one? That'd make sense, as currently the clients don't synchronize anything rate limit-wise.
You could try looking into webhooks then, as those are not tied to your bot/application.
Yeah webhooks were another option but it presents the problem that I never had the create webhook permission when I started ( and still don't ) so chances are most guilds won't allow me to create them
So I would need to go through all guilds and ask them to enable create webhook perms :/ kinda a pain and should have thought about it when I started but I was a noob + I had no idea it would become this popular
That would make lots of things simpler though but I dread having to convert everyone 😦
20000 messages in a second @mild shore ?
you want to send this amount, so fast?
whats the maximal time all messages should be sent?
you are using discord.js-light
then just do client.channels.forge(chanellid).send(message) (⚠️JUST DISCORD.JS-LIGHT)
this does not require any broadcastEVal and sends the request directly to the gateway
alternativly you could use client.api.get......
thats a good solution, then you have to save the webhook id and the webhook token in your db
Yes
yes
@valid gale
@fathom olive you are arabic bro and me is arabic
#archive-offtopic for handshakes and brofists please
Greetings! It's very funny, but my bot has disconnected on several servers, but I get information about all shards, and they are all online) is it possible to somehow synchronize the bot with these servers without restarting the rest?
Shard#respawn()
Kills and restarts the shard's process/worker.
do u also need to do the broadcastEval for the VOiceStateUpdate event?
I don't see how these two are related.
I'm going with "no".
What do you mean with "sharding process"?
but without it it wont work
if someone joins a channel in shard 3 i wanna join with the bot there not work
You need to elaborate on the "not work" part.
I don't understand, discord.js does not prevent you from exiting the process using process.exit.
I have a problem, from time to time the shards seem to come out of the ShardManager, which has the effect of creating double shards, i.e. duplicate commands. It was rare, but now it happens quite often. If someone has already had a problem like this, please contact me, it would be really nice of you.
Yes, that's correct.
You can use Shard#kill from within the manager process to not have the child process restart.
https://discord.js.org/#/docs/main/stable/class/Shard?scrollTo=kill
Client#shard is not a Shard.
You need to send a message to the manager process (using ShardClientUtil#send, that's what Client#shard).
This message needs to be received and handled by you from within the manager process using the Shard#messages event.
There you can then kill the shard.
What kind of sharding are you using? Internal? Traditional + process shards? Traditional + worker thread shards?
If you use worker threads you could potentially kill the whole bot at once
?docs ShardingManagerMode
When you create the ShardingManger, one of the options is a "mode", you can specify "worker" if you'd like to use worker threads. I believe it defaults to separate processes
Then when you do process.exit, it should kill the worker threads as well I believe
That's one option, if you want to keep using traditional sharding with processes, I think you'll have to kill each shard separately
Then follow the steps that space laid out for you
If you just want to restart the process, you already got that going, since d.js does that automatically.
no one ? I can't run my bot this make double commande quickly and i don't know from where it come
How are you spawning shards? Do you use ShardingManager.shardList?
Double commands can happen if you have 2 instances of the same shard ID running at the same time
I use sahrdmanager.spawn()
How can you check if there is a bot on a specific server if shards are used?
How do I use the load balancer in my bot Do you have a tutorial for Discord.js library?
client.shard.fetchClientValues()
It's doesn't work
Can you show the full code and console output?
This method only displays the number of users, servers, etc.
Can someone explain to me the difference between ShardingManager and pm2
The sharding manager manages the shards/subprocesses of the sharded bot, and pm2 is a node process manager
can i run my bot from multi host like 100 server in one host and 100 in other host ?
not with raw discord.js, you would have to implement the actual shard balancing yourself (you can tell each client what shards it should run on)
and honestly why do that at such a small scale
i have a hosting problem . my server have 16core and 32gb but the bot so lagy
in 2900 guilds
what the fuck
what is your bot doing
muisc bot
Maybe look into lavalink.
My bot has ~5k guilds and my 4 core 16GB server barley cares
oh and does it actually use all the resources?
if it lags in voice channels it's probably not going to be solved by having more hosts with less shards running on
Is creating clusters part of sharding?
How do I check total number of shards with internal sharding?
client.shard.count
"internal sharding" client.shard will be null
client.ws.shards.size
Checkout this guide on sharding: https://discordjs.guide/sharding/
so i've been starting to have shard disconnect and refuse to reconnect automatically. i'm at 12 shards right now. do i need to start looking into clustering?
https://github.com/discordjs/discord.js/pull/5222 This PR says that I should be able to broadcasteval to a specific shard while the bot is booting, yet it still throws an error when I do that.
When i run this file with node shard.js i get no error. I'm not exactly sure whats wrong other then that it is in the top.gg api area. If someone could help that would be awesome
Nvm missed a ;
Still need help w this
can i shard without 2000 servers
Yes
It's required when you hit 2,500 servers, but you can start it any time before that
just for testing ?
but will it harm any of my things in my project
cause i don't want my rpoject to get glicthed or destroy something like that ;-;
no, it wont harm anything, just follow the guide
I sharded when my bot was on 20 servers, for testing
ohh nice
Just read the docs as it'll tell you why sharding can be both good and bad, sharding is good for multiple servers as it splits to many clusters which have different pings. Although, this does drag down the bot and make it slower slightly, but is beneficial for 2k + bots
Slower?
🤔
How can you check if there is a bot on a specific server if shards are used? Pls, help 
what are you trying to do?
client.guilds.cache.get();
im asking more generally
what do you want from that guild
Check if there is a bot on this server
Can someone help with this?
can you provide any more info?
Turns out the error was something else, disregard my issue :)
does sharding have many functions ? i mean how much data can we fetch using vars with sharding ..
i mean should i need to learn all that variables for getting all that data ?
you cannot take out full objects out of the broadcastEval
this should explain <#archive-sharding message>
Anybody know little about this?
Reinstall the OS of the vps, install the dependencies and when you want to start it I get this
I would guess one of your shards errors and then the sharding manager complains because it isnt ready (because it threw an error)
Can shard X fetch a channel from shard Y, and send a message to it, without going through broadcastEval?
How I could fix it
"error: Cannot load default config file"
is maybe the error?
Maybe, but I don't know what that mistake might be, it doesn't say where it comes from
how do I make a slash command ephemeral
that is not a question related to sharding, nor does the library support interactions (yet), please see #useful-servers for an invite to dapi
is there a ETA?

Hi, what is this error?
Channel closed
I have:
const manager = new ShardingManager('./src/bot.js', {
token: Config.Bot.token,
});
manager.on('shardCreate', (shard) => console.log(`Launched shard ${shard.id}`));
manager.spawn();
After about a day, my 4th shard normally goes down without any type of error surfacing. I'm beginning to honestly think it's a RAM issue. But, my RAM only sits at around 62%. Any thoughts?
process.on('uncaughtException', (error) => {
console.error(error);
});
process.on('unhandledRejection', (error) => {
console.error(error);
});
client.login(Config.Bot.token);
Nothing is showcased from the client itself 
Do broadcastEval(), fetchClientValue(), etc have a timeout? I'm running into a weird scenario, where (what I think is going on) one of my shards is unresponsive, which causes broadcastEval(), fetchClientValue(), etc to not return and seem to just be waiting for a response forever.
it may have something to do with your bot loading before the shard manager. This wan an error with my bot, so just throw an async / await func and it should fix the problem.
Does not make it slower, infact it makes it faster, BUT sharding does increase memory usage
why am i getting Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready. everytime i start the bot?
Do you have the fetchAllMembers option enabled?
no
Default timeouts for everything?
yes
could it be caused by a slow connection?
It could be
I'd recommend logging the debug event and seeing what's going on
aight
when i pass an array through broadcastEval only the first element is carried over, how to pass the entirety of the array?
nvm, i passed it on the JSON.stringify function first to solve it
Wy are await Promise.all(...) not allowed in a broadcastEval script ?
They are?
Oh yeah, its not wrapped in an async function, you'll need to wrap it yourself
(i am in an async function ofc)
in the eval context probably not
uhh, i never did that, do you have any examples ?
(async () => { /* my async code */ })()
that's what i did
in the eval?
just show your code smh
hmmm
no ideas then ?
async => { is not a valid arrow func
oh
indeed, thank you
🙇
Hello, how can I wait until all shards are loaded?
What are you trying to do ?
<client>.fetchClientValues gives error when all shards aren't loaded
Error: [SHARDING_IN_PROGRESS]
I personally do const res = <client>.shard.fetchClientValues('something').catch(() => undefined);,
and then if (res.filter(r => r === undefined).length != 0) return message.reply('Not all shards ready');
it basically returns undefined if a shard is not ready, and then checks if any shard returned undefined
thx, in your case i'd some changed your code from .catch(() => undefined) to .catch(() => {}) cuz func by default returns undefined, but i think that you're way is easier to understand for you
Can someone help with my issue? https://github.com/Heptagram-Bot/Heptagram/issues/74
?shardreadytimeout
Got this error: Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.?
The spawnTimeout can be set to -1 or Infinity to prevent future errors:
https://discord.js.org/#/docs/main/stable/class/ShardingManager?scrollTo=spawn. This can also happen if you call ShardingManager#spawn before attaching a listener to the shardCreate event which could create a race condition possibly preventing the shard 0 to perform a successful launch.
@split nimbus
ups
i tried sharding but its not spawing any shards
why ? my bot is in 1 server that's why ?
it should spawn 1 shard atleast then ?🤔
should i add my bot in more server so that it will shard
This really should not be something to worry about until your client is in 2,000 guilds.
@buoyant oracle You dont need to shard till atleast 2000
but i wanted to test
at 20 servers it won't shard ?
unnecessary. even when you reach 2K guilds you can just turn on internal sharding til you reach 20k, so no need to test anything at 20 guilds
oh
is there a reason broadcastEval takes a string instead of a function? it seems much more intuitive to pass a function directly instead of evaling from a string, isn't it?
you can do that, as outlined in the sharding section of the guide
you can force it to shard with totalShards
You can pass an actual function into broadcastEval? I thought it has to be a string?
It can be a function -- if it is, we'll stringify the function and wrap it in an iife
What is sharding, and why do I need it?
Interesting, had no idea that function.toString() was a thing
.toString exists for all objects in javascript ;)
(but sometimes behave different)
see pinned messages.
as soon as you hit 2.5k Guilds you need sharding, should probably look into it before that
No. You can pass an actual function.
probably gets converted to a string somewhere, thats what I meant with that
script = typeof script === 'function' ? `(${script})(this)` : script;
https://github.com/discordjs/discord.js/blob/stable/src/sharding/ShardClientUtil.js#L139
guess d.js can handle functions, converts them to strings and calls them
@devout vine fyi
You have to wrap it in template strings, but the function itself doesn't have to be a string, again this is all outlined in the sharding guide.
client.shard.broadcastEval(`(${funcName})('${arg}')`);
how do I display the total guild count in the status?
I'm having problems with promises
This doesn't answer my question of why sharding is necessary
load balancing
what is that?
your balance your load.
imagine you have millions of guilds, you dont run that off a single server, you spread the load among many servers.
each shard handles x (reccomended is 2k - 2.5) guilds and each shard has its own websocket connection.
for more questions:
https://discord.com/developers/docs/topics/gateway#sharding
or the discord api server
Ohhh ok, ty
?warn @rugged sentinel please do not post invites here, especially not in support channels
Successfully warned misheutter#6147
Hello please help. I have a ratelimit i how to fix this?
i waiting for 1 hours
?shardreadytimeout
Got this error: Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.?
The spawnTimeout can be set to -1 or Infinity to prevent future errors:
https://discord.js.org/#/docs/main/stable/class/ShardingManager?scrollTo=spawn. This can also happen if you call ShardingManager#spawn before attaching a listener to the shardCreate event which could create a race condition possibly preventing the shard 0 to perform a successful launch.
and for the ratelimit, well you just have to wait for now until you can send requests again
how many shards i need for 3.5k servers?
Generally speaking, shards will have around 1000-1500 servers, so I'd say 3, but if you use the default settings, the recommendend amount will be used
ok 👍
ik i did it as 15 shards
each shard can hold 2.5k guilds.
Of course, but that's not relevant here.
Is there anyway to test sharding, I mean like can i make a sharding with a bot in 3 guilds or so, I'm just eager to know how the sharding would be, so its possible?
yes, just set the shardCount to whatever you want
for internal sharding its shardCount, with the shardingmanager its totalShards
sup, my bot is in 1800 servers and growing, should i start using shards?
most likely
so it's running for example index.js for every shard?
sharding with sharding manager runs copies of your code for every shard you are running
pain
another alternative is internal sharding, you need to change 1-3 lines of code that's it
not as scalable, but depending on what your bot does, it can probably take quite some shards (I currently run 5k guilds with internal sharding but I would guess 20k or more is doable)
Check the pins
@terse cairn bump
gonna use normal shards anyway probably
alright, just wanted to let you know of the alternative. In the worst case scenario you can buy yourself some time with internal sharding
I let a bot that makes miencraft kill, thanks to @terse cairn
no clue why you pinged me, but I have no clue what you're talking about nor have i helped you with anything 
sorry I missed with the tags :v
please keep this category to questions and problems, feel free to share accomplishments in #archive-offtopic though 
i think you must use javascript let user = message.channel.mentions.users.first();
no
?
Not sure why you even answered to that, since they didn't ask for help, but your answer is also wrong.
But this channel is no place to discuss that.
Hello, I have a question around sharding that i'm not able to really find anywhere. So it looks like traditional sharding is the most recommended for busy bots. However it also appears that traditional sharding simply separates the incoming messages over multiple processes on a single server.
How would traditional sharding work for say 10-20 ECS instances within a VPC?
traditional sharding on its own doesn't really care about much. all it does is spawn n instances of same code, and provides some communication between shards it runs
we don't really have any built-in way for supporting multiple sharding manager processes, but nothing stops you from having a separate api, service, redis or whatever you want to have some inter communication
though indeed, you can spawn only some shards on one sharding manager, and other shards on other one, sharding manager can take a list of shards to spawn afterall
So am i right in thinking – the purpose of sharding is not to directly split guilds, but instead split the load of requests over multiple processes. And so all shards will need access to the same cache in order to be able to fulfil a request?
I suppose secondly to that, my views on scalability are auto-scaling within AWS and it can scale based on CPU.
The alternative could be to have a single service that pushes the incoming requests into an SQS queue to be consumed and handled via the Discord API.
So neither of those can be achieved using Gateway, which unless i'm mistaken is the only method available to me?
with sharding manager there is no shared cache
each process is just a copy of your main file
only thing that is "shared" is way to communicate between the shards, mainly with broadcastEval or fetchclientValues
and you can't really change shard count on the fly that easily
Ah ok. so it basically sounds like it would be impossible for me to simply run my bot on multiple ECS instances.
well, not exactly impossible, but definitely not supported out of the box
you just can't really have it auto scale
you can have some shards on one instance, and other on second instance
but that's that
That was my worry 😦 then i suppose realistically how does bots like mee6 run?
by doing what i suggested
they have ways to communicate between servers, most likely with some form of internal api
I guess i'm cautious of a single server, how big would it need to be? how much ram/cpu will i need? what happens when i hit a physical limit
depends on the server and what the bot does
This may be my lack of understanding, but I can't see any physical way around scaling other than throwing more physical resource at something and load-balancing it. So in say software engineering one would simply set desireCount and run the same service and either consume from a message queue or the load-balancer would feed requests
yeah, but this isn't really possible from discord api standpoint
I would expect something similar for the bot, just i don't think Discord support that.
api in general needs your shard count when you identify
and you can't scale that out that easily without restarting
I see, so i'm struggling to see the alternative scaling method is all. I would rather auto-scale via AWS as that's more cost effective, scale when it needs and only pay for the resource i need
+large bots have certain specific shard counts they have to follow
Ah okay, that at least gives me something to think about.
unless your bot is extremely large or resource intensive, there is no point in auto-scaling it much
if your bot does something intensive, like image processing for example, you could think about separating that part out to its own server
then you don't have to worry that much about bot's main server running out of cpu
Oh i've got you. yeah i guess the sharded instance could be a single instance with multiple processes that pushes into SQS
then i can handle those from consumers and that way it frees cpu
consumers can scale based on SQS message number/size
could also use a separate gateway that pushes things to some queue, but this isn't really discord.js anymore at this point (d.js doesn't have separate gateway, and that won't come to it for quite a while)
yeah, that's true. I appreciate this info. I mean discojs is fine for my current bot and the bits im doing. It's my next bot/project... this has been very helpful

Is it possible to “break out” of bEval whenever i.e. a user has been found?
You should avoid to search for a user in a bEval in the first place I guess, what is it you'd like exactly? Getting a user is just client.users.fetch for an arbitrary shard.
When getting member info, you could only fetch the member in de bEval after a guild.id check from example
I’m fetching a user from cache and trying to DM them
You can just client.users.fetch(id) and the user.send from any shard you'd like, no bEval required
Note that his response will always be received on shard ID 0
How does d.js handle fetching? Does it check the cache across shards first before actually making a request to Discord?
No it only checks the cache on its own shard before fetching
But checking the cache on all shards sounds very inefficient
I see, I’m just trying to keep requests to Discord to a minimum. I’ll try your suggestion out, thanks!
hello! i have bot written in TypeScript & discord.js, i tried sharding so my bot can handle more than 2500 servers but i have some issues with dashboard. Dashboard runs normally because i made it starts with shardingmanager not with shard but my dashboard fetches data from client and here problem begins.
Luke.guilds.cache.get((guild.g.id as string))?.channels.cache || []
i tried to rewrite this but how? Actually
await Luke.shard?.broadcastEval(`this.guilds.cache.get(${guild.g.id})`)
doesn't work
Dashboard router without sharding: https://github.com/Nimplex/Luke/blob/main/src/dashboard/router.ts
it's running on 1 shard
but it sent two messages
What exactly does "run normally" imply? Also I'm not sure you need to figure out sharding just yet
I'll need later, run normally means execute command one time instead of 2-4 (or trigger event)
you cannot return full structures outside of broadcastEval
that's not problem anymore
the problem is thst bot is responding multiple times
Hello, could someone explain to me what the shards are for please? (Mp)
When your bot reaches 2500 servers, discord cant send all the data using 1 WS connection anymore, so you distribute the server over multiple shards
is there a way to fetch the guild cache collection object from every shard? I've tried everything with both broadcastEval and fetchClientValues
If you have access to ShardingManager/ShardClientUtil, you can use <Sharder>.broadcastEval() to broadcast a script to all of the shards.
If you wish to kill all of your shards, might as well shut down the whole bot.
It takes a normal line of code, just in a string.
But yes, process.kill() will shutdown that process.
ShardClientUtil#broadcastEval()
Evaluates a script or function on all shards, or a given shard, in the context of the {@link Client}s.
Forgot broadcastEval() has two arguments. You can provide the code string and a shard number.
shardDisconnect is fired when the websocket for the shard dies when the shard is in the ready state. So no, it won't fire when the shard itself is forceably killed.
It would be on the Shard itself.
(event) Shard#death
Emitted upon the shard's child process/worker exiting.
The event itself is called death, and it is on the Shard.
what'S the maximum amount of guilds each shard?
2500
but note that if you pass it, your bot will not be able to log in
You will not receive help with snipe commands, also this channel is for issues related to the sharding ecosystem
how to get guild using shardingmanager?
You don't actually, you cannot share D.JS structures between shards
then how to do this with multiple shards? client.guilds.cache.get(guild.g.id)
What is it youd like to do with the given guild?
fetch data.
name, channels, id, owner, (bot member)
Okay so that is information you can retrieve
Like broadcastEval const g = this.guilds.cache.get('id'); g && ({ name: g.name, id: g.id })
mhm i'll ty
Actually, I would broadcastEval this.guilds.cache.get('id')?.toJSON()
static void UpdatePresence()
{
DiscordRichPresence discordPresence;
memset(&discordPresence, 0, sizeof(discordPresence));
discordPresence.details = "setting up";
discordPresence.largeImageText = "Numbani";
discordPresence.smallImageText = "Rogue - Level 100";
discordPresence.partyId = "fff";
Discord_UpdatePresence(&discordPresence);
}
pretty sure that isnt javascript (nor typescript)
it is my rp sinko
damn thats crazy, but why are you sending it into this channel again?
because no one answered on help xd
wrong language genius
what lang
this is not a c#(?) server
this is a server for a javascript/typescript library, so unless you dont use one of those, wrong server
it is js
no its not
its c#
idk c#
either way, its not any language that we support here, please stop, thank you
lk py,html,java and some js
@terse cairn keep offtopic discussions out of the support channels.
Shard 1's Client took too long to become ready.
Any idea why this happens?
The shards client took too long to become ready lol
You can increase the time the ShardingManager waits for the client to spawn with the spawnTimeout option
?docs ShardingManager#spawn
Hi, when testing sharding how do I make a bot with 2 servers and property 'totalShards: 2' assign each server to a different shard?
Right now my sharding manager spawns two shards but but both servers are on shard 1 and shard 0 is empty 🤔
Alright. Me and 3 other people are all hosting the same bot on our virtual private servers. We used the built in sharding manager and all took several shards.
Recently I had to restart my vps and just everything broke. With the same code and everything, my vps takes all shards and when restarting all hosts, the two other hosts both take shard 0 and mine all the shards again.
Does anyone have a clue what could cause that?
bot goes offline right after it is online
and i ain't sharding soo idk?
and thats related to sharding because?
I know, but the error continues without reason
Shard 1 refuses to start
Could anyone help me? I have had the same problem for a while and I can't find any errors.
Shard 1 or Shard 0 (the first shard?)
And is it always the same shard? Do other shards start up normally?
Yes, the other shards start normal.
But within minutes they go off for no reason.
how do i check the ram usage of a shard
specify if you're using internal or traditional sharding, please
using const { ShardingManager } = require("discord.js"); assuming that means traditional
https://discordjs.guide/sharding/additional-information.html#specific-shards
but instead of exiting the process get the ram usage
tnx
Still running into this weird issue, but now have a little more info since I've added some debug logging.
I'm using Traditional sharding + worker thread mode (instead of process mode).
It appears that after my bot has been running awhile, one of the shard's clients (Shard 17 in my last case) becomes unresponsive. I get reports from some servers where the bot appears offline for them. I have added logging and can see that the specific client that fails no longer receives the broadcastEval command, which I've set to console.log() temporarily. I get no log from Shard 17. All other shards do log this event. And the ShardingManager's broadcastEval() never returns. It seems to be stuck waiting for that broken client to respond.
Is there any additional info I could log to see what's going on with the shard's client? fetchClientValue, broadcastEval, etc calls to the shard will run forever seemingly
Or any ideas what might be causing this?
Quick question about sharding. When it comes time to need to spawn a new shard, do I have to restart my bot for it to spawn or will djs do it automatically?
There's no need to spawn new shards while running, you can go over the 2500 guilds per shard during run time. If you set shards to auto, it will make the correct amount next time you start
Alright so I am sharding my bot. It is in about 8.5k servers yet the sharding manager is only spawning 1 shard. Is there a reason why that could happen?
At how many servers does a bot need to start sharding?
thanks
@terse cairn please read the pinned messages next time.
I still get this error while using broadcastEval(), which was said to resolve this over fetchClientVaules() at ready event.
it connects does not respond to the event, the status is not set since this afternoon
It's really weird and I think it's because of a server that it doesn't work anymore
discord.js version : 12.5.3
and have this
@pearl cove
sorry, but I have never used sharding, so I don't think I can help you much
What version of djs are you on?
12.5.3
When did the issue start?
today
17h france
If you’ve sharped before without problems it’s probably just discord
but my bot is not working anymore because of this and I didn't change my code it just happened all of a sudden
that error is because of stage channels iirc
I have that too, besides those warnings I dont have problems with it
Stage channels make fetchInvite bug
@pliant tiger this channel is for issues related to the sharding functionality of the lib.
Ok 😅 where is the bug report channel ?
on github
Hi all, sometimes my bot double-posts when responding to commands. It seems this is due to the sharding. After the bot has been online for a while, stopping the shard manager process leaves some instances of the bot running, which indicates that some extras are being spawned somehow. Is there a solution for this?
In the meantime I've had to use cron to stop the shard manager process, kill all extra instances and restart the shard manager
Please help me out here, I've been recieving tons of bug reports for the past month and I've got no idea how to resolve this 😦
Isn't this a regression? I remember a ticket that had the same problem... shards running after the parent dies
I don't know and can't really look rn, an Idea would have is to use client.shard.send and something in the master process to have a heartbeat, and as soon as those don't arrive anymore you can assume the parent process is gone
Assuming this is really an issue with orphan processes
Isn't this a regression?
It is a regression, but the reason my bot didn't exhbitit this behaviour before is because it was on DJS 11. This happened after porting it to 12. The sharding code is very simple though.
Assuming this is really an issue with orphan processes
Fairly certain it is. If I runpm2 stop botto kill the shard manager, then runhtopI can still see the orphaned processes running
..master process to have a heartbeat
This heartbeat idea is interesting, I'll look into it. The double posting is driving me crazy
Nevermind, seems like it was never merged, so not a regression
You would have to experiment but you can probably simplify this by checking if the IPC channel is not disconnected yet
but the heartbeat approach would be more reliable
So yeah, try the following:
ShardingManager#shards
A collection of shards that this manager has spawned
iterate through that and regularly send a heartbeat to shards, shards should be able to check with
ShardClientUtil#parentPort
Message port for the master process (only when {@link ShardClientUtil#mode} is worker)
should have a message event, I don't know how the messages will look, you just need to try it out
a simpler alternative would be (if this doesn't work) to check when the parentPort closes (it has a close event and various other events), in theory it should close when the parent dies, but I don't know if this is actually true. Just test a bit around
@austere osprey bump
prolly should not test in production lol
I actually made a PR about this but totally forgot to update it. I'll open up a new PR that fixes ghost processes.
||isn't it orphan tho||
well, yes, wasn't thinking 
What would be the proper method of getting client.commands
No idea, as it isn't a djs problem.
it has to do with sharding...
if I do a regular eval, it returns it correctly
fixed, doing .array() fixed it
Thank you ❤️
bot goes offline right after it is online
and i ain't sharding soo idk?
even if its sharding how do i know?
Does bot.on("guildCreate", guild => { }) work always for all shards?
or only works in 1 shard?
A guild can only be on one shard at the time
I mean, i just want a log, that will notify me whenever my bot joins any server in any shard.
Sorry, i think you didnt get my question, thats my fault coz i couldnt describe the question properly.
Will this event emit whenever my bot joins any server in any shard?
are you using sharding manager?
bot.on("guildCreate", guild => {
const added = new MessageEmbed()
.setColor(color)
.setTitle(`${guild.name} - ${guild.id}`)
.addField("Guild Members", guild.memberCount)
.setImage(guild.icon)
.setThumbnail(
"https://cdn.discordapp.com/emojis/467569397981118495.png?v=1"
);
const channelId = "692711072444055623";
bot.shard.broadcastEval(`const channel = this.channels.cache.get("${channelId}"); if (channel) channel.send(added)`);
})```
yeah, you are
sharding manager runs multiple copies of the main file
And, wanted to know, if this is how the broadcastEval() works
each copy is one shard
script parameter as a string
should work, apart from the fact that you don't have added as a string
or as a variable
added is my embed
no, it's a string
so i have to use it as channel.send("added") ?
that will send added as a string, yes
but as you can even see in the codeblock itself, it's just some letters in the string
I dont want to be sent as a string, added is defined as my embed
it's not the embed
look at the difference between the channelId and added
the channelId is a template literal and will get resolved to a variable
the added there is just a meaningless part of the string
channel.send("${added}")
yes. and this is where the hard part starts
you can't really put full discord.js structures in or out of the broadcastEval
if it would be outside the broadCastEval()
we usually do channel.send(added) simply, but when its inside broadCastEval() why its different?
cause you're passing a string
oh
send('9touhglihglkidfhdilhbvf') sends a string
broadcastEval on its own takes a string
so you have to use template literals to fill in variables
isntead of just having a srting
solved it, not cuz of sharding. and i dont shard private bots
hmm got it
anyway
you can't put embed like that
const channelId = "692711072444055623";
bot.shard.broadcastEval(`const channel = this.channels.cache.get("${channelId}"); if (channel) channel.send("${added}")`);```
should work fine now?
not really
damn do i have to define the embed variable inside the broadCastEval() then?
let me write full message
ok
since broadcastEval takes a string, you have to pass a string. template literals basically stringify whatever gets passed to it. MessageEmbed isn't a string, so doing MessageEmbed.toString() results in [object Object] and not your embed - this means it will not work.
to actually have an embed passed from outside of broadcastEval, you have to do ${JSON.stringify(added.toJSON())} - this will turn MessageEmbed into plain JSON object, and stringify it, making it possible to be used in the broadcastEval.
alternatively, you can just create that embed inside of the broadcastEval and use it like you would normally.
similiar thing goes for taking things outside of broadcastEval - you can't take out most of library structures out like this - look here #archive-sharding message
wow, thanks for the well explanation 👏
bot.on("guildMemberRemove", async member => {
if (member.guild.id !== "692047883062738975") return;
let embed = new MessageEmbed()
.setTitle(`Bye bye ${member.user.username}`)
.setDescription("Bye from Corona Support Server")
.setColor(color);
bot.shard.broadcastEval(` var byechannel = bot.channels.resolve("692711072444055623");
byechannel.send({"${JSON.stringify(embed.toJSON())}"});`)
});```
did i just get it now?
without the "s, but should do, yes
your sending embed, not a string after all (send(embed), not send('embed'))
note that resolve doesn't always return the channel, so the part you had before was more error resistant
const channelId = "692711072444055623";
bot.shard.broadcastEval(`const channel = this.channels.cache.get("${channelId}"); if (channel) channel.send("${JSON.stringify(added.toJSON())}")`);
this part?
it should be channel.send("${JSON.stringify(added.toJSON())}")
or channel.send(${JSON.stringify(added.toJSON())})
actually, wait
mm
you have to do send({ embed: ${JSON.stringify(added.toJSON())} }), since it's an object and not MessageEmbed
and i was talking about const channel = this.channels.cache.get(); if (channel) channel.send()
why sharded bot is hard af 😂
it really isn't
this here is p much just related to making a string out of MessageEmbed you can use somewhere else 
bot.shard.broadcastEval(`const channel = this.channels.cache.get("${channelId}"); if (channel) channel.send({ embed: ${JSON.stringify(added.toJSON())} )`);
should work
bot.on("guildMemberAdd", async member => {
if (member.guild.id !== "692047883062738975") return;
let embed = new MessageEmbed()
.setTitle(`Welcome ${member.user.username}`)
.setDescription("Welcome to Corona Support Server")
.setColor(color);
const channelID = "692711072444055623"
bot.shard.broadcastEval(`var welcomechannel = this.channels.cache.get("${channelID}");
welcomechannel.send({embed: ${JSON.stringify(embed.toJSON())}});`)
});```
i just mentioned why the previous way of getting the channel was better
oh yes!
edited
5|x | logged in as Corona Stats#4983
5|x | Error [SHARDING_IN_PROCESS]: Shards are still being spawned.
5|x | at ShardingManager._performOnShards (/root/covid/node_modules/discord.js/src/sharding/ShardingManager.js:258:75)
5|x | at ShardingManager.fetchClientValues (/root/covid/node_modules/discord.js/src/sharding/ShardingManager.js:245:17)
5|x | at Shard._handleMessage (/root/covid/node_modules/discord.js/src/sharding/Shard.js:338:22)
5|x | at ChildProcess.emit (events.js:314:20)
5|x | at emit (internal/child_process.js:877:12)
5|x | at processTicksAndRejections (internal/process/task_queues.js:85:21)
5|x | Launched shard 1```
any idea why i always get this error? low ram ?
probably fetching client values while shards are still spawning
do i have to run guild.owner.send() inside broadCastEval() as well?
if you want
x | (node:24262) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of null
that means i have to right?
bot.shard.broadcastEval(`guild.owner.send("Thanks for adding me in ${guild.name} ! You can use .help to discover commands. here is our support server link: \n , you can support us by voting: https://top.gg/bot/691936549243191346/vote");`)```
?
guild.owner is undefined
*null
try fetching the user
Guild#ownerID
The user ID of this guild's owner
you may not have intents
No. Guild#owner is a nullable property. you should fetch it before accesing it as laid out above.
if you have not intents you can't fetch ;P
?owner
Guild#owner is a nullable property which relies on cache. Fetch the owner through GuildMemberManager#fetch() using Guild#ownerID.
If ur just dming, then you can just fetch them as a user
@dense cape @valid gale Wait.... But if i do not have guild member intents i can not fetch users 🤔 so...
What?
@dense cape adrian reacted no
Guild members intent doesn’t affect users
wait what is that
So i can fetch the user?
Yes
WE ngrioqwg n[rowign rw0iodcgnqpwiemfcopqemxfi;
Brain fucked now
Hey! So I was editing the webpacks because discord.stable.min.js wasn't working, and I almost got it working. However, now I'm facing the error of Uncaught Error: The shardCount option must be a number greater than or equal to 1 when I try to start the bot via the browser.
Nvm, fixed the error.
hihi, I suggested this xD #archive-guide-discussion message
Been using it before
what even is sharding?
check the pinned messages
Why I cannot get channels that are in other shards?
Ping me when you see this pls
That's how sharing works, you create instances of your client that only handle a part of the total guilds. You can use broadcast eval tho to for example send a message in a channel you can access
can u show me how?
i have already tried but I couldn't firgured out how it works
client.shard.broadcastEval("client.channels.get('some ID')?.send('some message')")
For example
Up to how many shards can u have?
there is not such thing as shard limit
only barrier is identify limit
why does the lib throw if a shard isn't ready "in time", why doesn't it continue with the remaining shards in queue?
also, why doesn't the lib respect the spawn delay? why does it need for the previous shard to mark ready? I would expect the sharding manager to spawn shards every 5 seconds if i tell it to for an example, but it spawns the next shard until the previous marks ready regardless of the spawn delay i set
When using optional chaining please make clear that it requires node 14+
Thanks
hello, after I changed the shards number to 2 shards after my bot rached 2.5k servers, the ram consumption tripled, is it normal or I'm missing a configuration
When you shard, it spawns an instance per shard.
So if you had 1 shard before that used 250mb of RAM, once you spawn another shard, it can double to 500mb of RAM.
is there a way to split the cache ? each shard caches only the servers it has
For internal sharding, the cache is shared. Process/worker-thread sharding have separate cache because they run in separate threads or processes, and they only cache guilds they have
this should work when trying to find a user with broadcast eval right?
let member = client.shard.broadcastEval("client.users.cache.get(args[0])")
It would not, you cannot share D.JS strucutes between shards, so you cannot get the full User object, you can get properties form the user object, or execute methods on the user object inside the broadcastEval
and this? this should work right?
const channel = client.shard.broadcastEval("client.channels.cache.get('832169994141302794')")
quick question, do each spawned shard execute the passed file on the ShardManager constructor to instantiate each shard's client?
did you actually read the answer above you
he was talking about the user object
It would not, you cannot share D.JS strucutes between shards
what do you think a channel is
Can't you fetch a channel though
Ok so you see bots creating "clusters" with sharding, is this done with the option shardLists ?
Disclaimer: I haven't used any of this, I'm just explaining how I think it works and from looking at code
I would guess they mix internal sharding (ClientOptions#shards) with custom process sharding,
e.g. you have 12 shards
you spawn 3 processes and each process handles 4 shards (with internal sharding).
a library that implements this, is https://github.com/DevYukine/Kurasuta
Why we can not pass function in broadcastEval ?
you can, but it will simply get converted to a string, and evaled by the other process
it should work, depending on the function you pass in (or its content)
So why it is recommended to put string?
is it?
idk, everyone using string version
maybe because they dont know you can pass functions, idk
Error: ENOENT: no such file or directory, stat 'C:\Users\Silver\Desktop\A_Learn\Cyspace\cyspace' at Object.statSync (fs.js:1016:3) at new ShardingManager (C:\Users\Silver\Desktop\A_Learn\Cyspace\node_modules\discord.js\src\sharding\ShardingManager.js:61:22) at Object.<anonymous> (C:\Users\Silver\Desktop\A_Learn\Cyspace\dist\sharding.js:4:17) at Module._compile (internal/modules/cjs/loader.js:1137:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10) at Module.load (internal/modules/cjs/loader.js:985:32) at Function.Module._load (internal/modules/cjs/loader.js:878:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) at internal/main/run_main_module.js:17:47 { errno: -4058, syscall: 'stat', code: 'ENOENT', path: 'C:\\Users\\Silver\\Desktop\\A_Learn\\Cyspace\\cyspace' }
my sharding file
const { ShardingManager } = require('discord.js');
const { TOKENS } = require('./config');
const { info } = require('./lib/logger/logger');
const manager = new ShardingManager('./cyspace', { token: TOKENS.BOT_TOKEN});
manager.on('shardCreate', shard => info(`Launched shard ${shard.id}`));
manager.spawn();
My main file
const Discord = require('discord.js');
const { onReady } = require('./lib/events/onReady')
const { TOKENS } = require('./config.js');
const client = new Discord.Client();
client.on('ready', (message) => { onReady(client) });
client.login(TOKENS.BOT_TOKEN)
you sure that your bot file is called cyspace and not cyspace.js?
a js file without js extension?
you're passing './cyspace' without an extension
same error after passing cyspace.js
my file structure
is the file in a folder or in the root of the project?
in a folder named dist
then you also need to add that to the path
ok one quick question
can i use sharding on my new bot
you can, there's just no reason to if your bot is in a small amount of guilds
thanks
is it possible to use a GuildEmoji from a guild from another shard to react on a message on a different shard?
you can just use id to react, but if you really need to have full object for whatever reason, https://discordjs.guide/sharding/extended.html#using-functions-continued
oh, thanks. I just need the ID. Didn't know (or i forgot) it was possible.
👍

Hello, my bot shard 2 just keeps starting up
https://cdn.discordapp.com/attachments/653572279485333505/832341209485279242/unknown.png
do you know why ?
If ur on node v. 15, unhandled rejections are deprecated and will crash
I'm in v12.18.0 of nodejs
which version do I install ?
That should be fine. Hard to say what's killing ur shard
hm
is there any more info? d.js version at least?
we made the update of Node.Js
How do I find what shard is the bot in? Like there is shard 0, 1, 2, 3, 4, 5 so for example, im in shard 1 and have this stats command. How will the bot tell me that im in shard 1 (ofc through a message but how do I display the shard its on?)
message.guild.shardID```
thx
What does manager.broadcast do, and how can I recieve the messages
how can i do multi-host sharding? i've looked on the docs and guide and have found nothing.
You would need to implement this on your own, 98% of d.js users don't need this so writing a guide on it is wasted lifetime
or there is a library that helps with that, but I only know of same host sharding
alright
It's fairly simple, you just run multiple instances on multiple hosts and tell each instance to only handle a certain set of shards
so like i could have a docker service, all running the bot container, all on different servers though, and all those bot containers have sharding enabled?
yeah, but you have to tell each instance what shards to run
right, so i'd need some kind of master bot / controller
depends, could probably have each host communicate with each other over a database so you don't have a master, depends how you wanna setup/program your infrastructur
yeah ofc
@abstract lichen (sorry for ping) I took your advice and used Kurasuta but it doesn't seem to log in / ready (I get Error: Cluster 0 failed to start), the GH page said if that happens, that the API never emits READY. any ideas?
Nope, never used it and not really djs related.
I would try just copy pasting the exact example and if that doesn't work... I don't know, open a gh issue or something
alright, sounds good
are you using a custom client?
make sure to pass options along in your constructor
should we do sharding of bot is in 150 guilds
It's unnecessary at that size
yeah i'm using akairo
i saw that issue and i tried it, i’ll send some code here later when i’m back at my PC
alright here's the code
client:
class NyxxClient extends AkairoClient {
...
constructor(clientOptions: ClientOptions) {
super({
ownerID: ['401792058970603539', '162305223589756928'],
}, {
...clientOptions,
});
...
}
async init(): Promise<this> {
...
}
}
cluster:
export class NyxxCluster extends BaseCluster {
public client!: NyxxClient;
logger: typeof Log
constructor(...args: [ShardingManager]) {
super(...args);
this.client.cluster = this;
Log.setSettings({
prefix: [`Cluster ${this.id}`],
});
this.logger = Log;
}
async launch(): Promise<void> {
this.logger.info('Initializing Client...');
this.client.init().then(() => {
this.logger.info('Client initialized!');
}).catch((err) => {
this.logger.fatal('Failed to initialize client', err);
throw err;
});
this.logger.info('Logging in...');
this.client.login(process.env.BOT_TOKEN).then(() => {
this.logger.info('Client Logged in!');
}).catch((err) => {
this.logger.fatal('Failed to log in', err);
throw err;
});
}
}
index:
const Sharder = new ShardingManager(join(__dirname, 'struct', 'Cluster'), {
client: NyxxClient,
development: (process.env.NODE_ENV !== 'production'),
respawn: (process.env.NODE_ENV === 'production'),
retry: true,
token: process.env.BOT_TOKEN,
shardCount: 1,
timeout: 120000,
});
Sharder.on(SharderEvents.DEBUG, (message: string) => {
Log.debug(message);
});
Sharder.spawn().catch((err) => {
Log.fatal(err);
throw err;
});
what is your error? @real lava
after 30 seconds, the default timeout, it errors just by saying "Cluster 0 failed to start". extending the timeout does nothing.
full err trace
(node:30584) UnhandledPromiseRejectionWarning: Error: Cluster 0 failed to start
at ShardingManager.spawn (D:\Code\Nyxx\node_modules\kurasuta\src\Sharding\ShardingManager.ts:117:37)
@crisp coyote any ideas? jw
not really stuff looks fine

can you log the custom client options which kurasuta is passing?
help-me
Update d.js to 12.5.3
Ok thanks
sure
<ref *1> ShardingManager {
_events: [Object: null prototype] { debug: [Function (anonymous)] },
_eventsCount: 1,
_maxListeners: undefined,
path: 'D:\\Code\\Nyxx\\src\\struct\\NyxxCluster',
clusters: Map(0) {},
clusterCount: 16,
guildsPerShard: 1000,
clientOptions: {},
development: true,
shardCount: 1,
client: [class NyxxClient extends AkairoClient],
respawn: false,
ipcSocket: 9999,
retry: true,
timeout: 30000,
token: '...',
nodeArgs: undefined,
ipc: MasterIPC {
_events: [Object: null prototype] {
debug: [Function (anonymous)],
error: [Function (anonymous)]
},
_eventsCount: 2,
_maxListeners: undefined,
manager: [Circular *1],
server: Server {
_events: [Object: null prototype],
_eventsCount: 4,
_maxListeners: undefined,
sockets: Map(0) {},
status: 3,
name: 'Master',
server: [Server],
[Symbol(kCapture)]: false
},
[Symbol(kCapture)]: false
},
[Symbol(kCapture)]: false
}
that's in the constructor, ClientOptions
hi, I'm working on sharding for my bot, and I have some information I want all shards to be able to access and modify (if a shard modifies the information, I need it to be modified for each shard).
Is there a way I could do this easily? I've tried a few things that haven't worked so far, and I'm a complete beginner when it comes to sharding so I have no experience.
Any help would be much appreciated!
a database
preferable a database server (postgresql, mongo, redis, whatever you want)
hmmm that's what I was trying to avoid lol. Oh well, if it's the only solution it'll have to do
Your message describes the exact use case for a database. I don't know what other option there would be?
UnhandledPromiseRejectionWarning: Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too
long to become ready.```
Any workaround for this?
?shardreadytimeout
Got this error: Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.?
The spawnTimeout can be set to -1 or Infinity to prevent future errors:
https://discord.js.org/#/docs/main/stable/class/ShardingManager?scrollTo=spawn. This can also happen if you call ShardingManager#spawn before attaching a listener to the shardCreate event which could create a race condition possibly preventing the shard 0 to perform a successful launch.
?shard
const { ShardingManager } = require('discord.js');
const Manager = new ShardingManager('./bot.js', { token: 'your-token' });
Manager.spawn();
https://discord.js.org/#/docs/main/stable/class/ShardingManager
For an in-depth guide: https://discordjs.guide/sharding/
the issue is a it's scores that then need to be sorted, so I'd need to pull from the DB and then sort all the items, pretty easy to do but can pretty slow (takes about 2 secs atm, and that time will only get worse)
Ideally I'd want some sort of pre sorted list/array in memory I could just pull the corresponding elements from, but I can't find a way to do that (if it even exists)
have you considered using a db that can sort
or use redis
hmmm what DB would be able to do that? I haven't thought of it at all
any sql db? order by
so does that mean the DB stores the items already sorted, so runs a sorting algorithm when you call the DB?
you can use redis to have in memory arrays/lists
looking into it now, looks like it's what I need
or use a db that can sort before it returns your data, I bet most database servers do heavy optimizations on repetetive queries
but yeah, if you are looking for fast in memory operations, look into redis
the one I use (sequelize, from the discord.js tutorial, I never bothered to learn a new one), takes about 1s to order the data, need it needs to be sorted. I haven't really looked into having it sorted before hand (didn't think it was possible)
But yea the bulk of the time is pulling from the DB, so I'd say redis is the way to go
ty for the info 🙂
sequelize with what database?
because sequelize is just an orm, it uses whatever database you tell it to, assuming sequelize is not completely stupid, its not important, its important how fast the database behind it can be
hmmm I didn't know that, haven't looked into it at all.
Is sqlite3 a database? I had to install that with sequelize when I followed the tutorial
change that then asap
sqlite3 is not ideal in a sharded enviroment
as far as I know
ah okay, so something like mysql would be much better?
I'm not a fan of mysql, but it would do. I would recommend postgresql
okay more stuff to look into lol.
I'm doing a lot of rewriting before sharding anyways, so it's 100% the time to do this kind of stuff
okay so see #archive-offtopic
sqlite can probably handle more concurrent than I think, I just often had bad performance with it
if you have the time, just compare both, imo
Hmmm okay.
Well I'm not asking to much. Writing some data a few times a min, and if I implement memory caching I won't be reading huge amounts of data at once.
Also I'm used to using it which as a definite advantage, but I'll be sure to check out postgresql
Also I'm used to using it
wdym?
you can just tell sequelize to connect to a postgres server instead, it probably takes barley any code changes at all
only thing you might have to worry about is migrating the data
Oh okay, now I get what sequelize is!
Migrating the data shouldn't be to hard with a simple for loop ig, even if there are better ways it's only a 1 time thing so I won't think about it too hard
how to tag a discord channel by id? command in Js
Don’t crosspost
What's the best option between process and worker for ShardingManagerMode?
I might not be djs-related, but I don't get the difference between the two options
worker uses worker_threads
Unable to parse received data, but maybe this is useful: https://nodejs.org/api/worker_threads.html
I'm already reading that
The only diff is that they share memory?
yeah, but dunno how big the difference is
Workers are just threads running on a single process iirc
I don't need my shards to interact so i think i'll use process
uh ok?
yeah wdc sorry
processes still interact with each other over ipc channels but ok
shard.on("death", (error) => {
console.log(chalk.red(`SHARD #${shard.id} DIED!`));
console.error(error);
shard.respawn()
.then(() => console.log(chalk.green(`SHARD #${shard.id} WAS RESPAWED!`)))
.catch(() => console.log(chalk.red(`SHARD #${shard.id} WAS NOT RESPAWNED!`)));
});
Is this a good way of handling death/errors on shards? Should I respawn the shard right after the error was caught, should I wait (more than 500ms) or should I leave the shard dead to prevent further errors from happening?
shard
Shard respawns are automatic if you have the respawn option enabled in the ShardingManager options. There shouldn't be a reason for you to be manually handling the respawns.
@crisp coyote hate to bother you, but are you still able to help me with this?
'kay i'll remove this part
?shardreadytimeout
Got this error: Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.?
The spawnTimeout can be set to -1 or Infinity to prevent future errors:
https://discord.js.org/#/docs/main/stable/class/ShardingManager?scrollTo=spawn. This can also happen if you call ShardingManager#spawn before attaching a listener to the shardCreate event which could create a race condition possibly preventing the shard 0 to perform a successful launch.
stop.ts I was going to help them :(
there is a tag
Please keep the support channels on topic.
whats the easiest way to find the guild count of a sharded bot?
the sharding section of the guide does this with detailed explanations
oh, djs has an inbuilt sharding manager?
thats really nice
thanks, found the link
if (message.content === prefix +'help')
how do i make that work, so that i can use prefix
Wrong channel
pls help{
?r4
4. When asking for help, make sure to provide as much detail as possible. Simply saying, "it's broke yo", or "how 2 make music bot" certainly won't get either of us anywhere.
When is shardError emitted? I tried to manually throw an error in my client's code, the shard dies then is respawned, but I don't receive any shardError event.
i'm using Kurasuta as some here have recommended for sharding, but my bot never starts. says "Cluster 0 failed to start" and it hit the timeout so it "took too long". setting the timeout to -1 or Infinity did nothing. if i remove the sharding and just use the bot normally (since i'm using discord-akairo) the bot starts fine, so it's not an issue with the bot token. what do i do?
Error [SHARDING_NO_CHILD_EXISTS]: Shard 32 has no active process or worker.
This will happen after a few days. Because it takes so long, and happens so randomly, I can't figure out the cause. No errors are thrown on 32 to knock it offline. :-/
https://github.com/discordjs/discord.js/issues/3956
Anybody know how to fix it in v12? My bot cant login from any IP/PC for about 2 days
dont help
I get this error randomly when starting my bot
hello guys, I'm trying to create a bot and I want him to do the following thing, when a new member enters the server he will check the day the account is created and if the account is less than 7 days old for example I want him to a special position for her, how can I do that? please send me a code example.
that's not really related to sharding
and please don't crosspost
Are ratelimits per application/token or per shard?
No, it’s per bot user
Is it possible to force a guild to be in the shard #0 so that I can start sending messages to that guild even if the other shards are not loaded yet?
is there a minimum required amount of servers before you can start sharding? I'm interested in messing around with it for several reasons, but wanted to be sure if it'd even work with only ~1400 servers
technically no iirc @wispy ocean
thanks
yup!
What may be happening is that shard is running into an error, because of the undefined guild, and either exiting the process or preventing it from signalling a ready state..
An easy way to check if it's an error causing your shard from spawning, throw this at the top of the file that initiates each client (not the sharding manager):
process
.on( 'uncaughtException', console.error )
.on( 'unhandledRejection', console.error );
const bot = new Discord.Client( {
//... Etc...
Important note, do not rely on this as a lazy means of catching errors. You should always have proper error handling/logging. However, it should get your shards to ready, and therefore get you to where you can better debug the issue.
Also, not sure if it'll help, consider upping the timeout.
it can be bc of insufficient ressources....
The Error means that Shard 32 lost their worker/process ===> you have to create a new worker_thread or child_process, when you have respawn enabled ==> it willl create a new worker/process
Resources in terms of what? It's running on a very costly VPS, so it's not low on memory, storage, etc. My current solution is to just have the sharding manager respawn it when it happens, but I want to prevent it from happening.
you can't, thats probably a node problem, respawn is the only way to keep them alive
is it possible to make a specific shard online or offline ?
at how many guilds should one switch from internal to traditional sharding
Hello !
My Discord bot has reached 2 500 servers, so I have to use the shards system.
Here is what I do:
const { Client, Collection } = require("discord.js");
const { readdir } = require("fs");
const Enmap = require("enmap");
const express = require("express");
const bodyParser = require("body-parser");
const { bot, settingsDbl } = require("./config.json");
const { reportError, setClient } = require("./Utils/loggingManager.js");
const client = new Client({ DisableMentionType: "all" });
client.commands = new Collection();
client.database = { };
client.database.servers = new Enmap({ name: "servers" });
client.database.msp = new Enmap({ name: "msp" });
const app = express();
app.use(bodyParser.json());
readdir("./Commands/", (error, files) => {
if (error) {
reportError(error);
}
let commands = files.filter(f => f.split(".").pop() === "js");
if (commands.length == 0) {
reportError("0 Commands!");
process.exit(1);
}
commands.forEach(commandFile => {
let command = require(`./Commands/${commandFile}`);
console.log(`Loaded ${commandFile}!`);
client.commands.set(command.help.name, command);
});
});
readdir("./Events/", (error, files) => {
if (error) {
reportError(error);
}
let events = files.filter(f => f.split(".").pop() === "js");
if (events.length == 0) {
reportError("0 Events!");
process.exit(1);
}
events.forEach(eventFile => {
let events = require(`./Events/${eventFile}`);
let event = eventFile.split(".")[0];
client.on(event, events.bind(null, client));
});
});
setClient(client);
my msp.js file the file I start :
const { bot } = require("./config.json");
const { ShardingManager } = require("discord.js");
const manager = new ShardingManager("./index.js", {
totalShards: 'auto',
token: bot.token
});
manager.on('shardCreate', (shard) => console.log(`Shard ${shard.id} launched`));
manager.spawn();
The problem is that I get this error: (node:13896) UnhandledPromiseRejectionWarning: Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.
I don't know how to solve this problem, can someone help me please?
You can mention me!
Do you even have the client.login call?
@terse cairn
no
because I thought it was already doing it with the shards system
I have to make it I think
Nah, that’s to get the sharding info, like number of shards to spawn
ah yes thank you it's work !
Also gotta be careful with hosting webserver bc it’s will run the index.js file once for every shard
Can’t have multiple servers on the same port, tho it doesn’t seem like ur using it atm
ahhh yes !
Better off putting it on the sharding manager file
yes 👍
thank you for this precision
Np
@dense cape how I can export the client in my msp file pls ?
What?
const { bot, settingsDbl } = require("./config.json");
const { ShardingManager } = require("discord.js");
const express = require("express");
const bodyParser = require("body-parser");
const manager = new ShardingManager("./index.js", {
totalShards: "auto",
token: bot.token
});
manager.on("shardCreate", (shard) => console.log(`Shard ${shard.id} launched`));
manager.spawn();
const app = express();
app.use(bodyParser.json());
app.post("/webhooks_bot", (req, res) => {
res.sendStatus(200);
if (req.headers.authorization === settingsDbl.authorization_bot) {
const user = req.body.user;
client.channels.cache.get(settingsDbl.channel_bot).send(`:arrow_up: | <@${user}> (\`${user}\`) has just voted for **${client.user.username}**, thank you! https://top.gg/bot/${client.user.id}/vote`);
}});
app.listen(settingsDbl.port, () => {
console.log("The server is online !");
})
?sharding
const { ShardingManager } = require('discord.js');
const Manager = new ShardingManager('./bot.js', { token: 'your-token' });
Manager.spawn();
https://discord.js.org/#/docs/main/stable/class/ShardingManager
For an in-depth guide: https://discordjs.guide/sharding/
I need it to send a message
Use Manager.broadcastEval
👍
Nice, thx
@dense cape Hum, I have an error :
manager.broadcastEval("this.channels.cache.get(settingsDbl.channel_bot).send(`:arrow_up: | <@${user}> (\`${user}\`) has just voted for **${this.user.username}**, thank you! https://top.gg/bot/${this.user.id}/vote`)", 0);
(node:16119) UnhandledPromiseRejectionWarning: SyntaxError: missing ) after argument list
it's a code error, but what ?
you can ping me 🙂
okay nobody
const { MessageEmbed } = require("discord.js");
const { bot, settingsLogs, settingsEmbed, settingsEmojis } = require("../config");
module.exports = async(client, guild) => {
const database = client.database.servers;
if (database.get(guild.id)) {
} else {
database.set(guild.id, {
prefix: bot.defaultPrefix
});
}
const channel = client.shard.broadcastEval("this.channels.cache.get(\"767016401361043456\")");
const vocal = client.shard.broadcastEval("this.channels.cache.get(\"768867402204577792\")");
let servers = await client.shard.broadcastEval("this.guilds.cache.size");
const reducer = (accumulator, currentValue) => accumulator + currentValue;
servers = servers.reduce(reducer);
vocal.edit({ name: `📡 ${servers} servers` }, `i joined ${guild.name} (${guild.id})`);
}
Otherwise, I don't understand how I can get a channel
event : guildCreate
everything is more complicated with shards
how I can get my channel ?
const channel = client.channels.cache.get("ID");
now it's not this bc I use shards
I am very confused, I don't know how it works and my bot doesn't work :CCCC
ping me pls ^^
You can’t receive a proper channel across shards
Well, you can’t make any api calls with it
ah ???
It is no longer possible to get a channel?
There must be a way, no ?

ahh okay
client.shard.broadcastEval(`
(async () => {
let channel = this.channels.cache.get('id');
let msg;
if (channel) {
msg = await channel.messages.fetch('id').then(m => m.id);
}
return msg;
})();
`);
so :
const channel = await client.shard.broadcastEval(`
(async () => {
let channel = await this.channels.cache.get("767016401361043456");
return channel;
})();
`);
console.log(channel);
const vocal = await client.shard.broadcastEval(`
(async () => {
let channel = await this.channels.cache.get("768867402204577792");
return channel;
})();
`);
let servers = await client.shard.broadcastEval("this.guilds.cache.size");
const reducer = (accumulator, currentValue) => accumulator + currentValue;
servers = servers.reduce(reducer);
vocal.edit({ name: `📡 ${servers} servers` }, `i joined ${guild.name} (${guild.id})`);
It's don't work, I log channel, and it's an array :C
[
{
type: 'text',
deleted: false,
id: '767016401361043456',
name: 'join',
rawPosition: 9,
parentID: '767016289994145802',
permissionOverwrites: [
'676860457935437863',
'676860851948355616',
'764580414391058483'
],
topic: 'ℹ️ When a person invite the bot, a message ' +
'will appear here! Link: ' +
'https://bit.ly/bot-msp',
nsfw: false,
lastMessageID: '833634163063259183',
rateLimitPerUser: 0,
lastPinTimestamp: null,
guild: '676860457935437863',
messages: [],
createdTimestamp: 1602941360560
}
]
an idea pls ?
ping me
Just get the first index?
like channel[0] ?
no, don't work
child processes can share the same port !?
webserver
oh
They were abt to run webservers on the shard file
a question, how do I set different presences on internal shards?
do I have to do a for loop on client.on('ready') ?
https://discord.js.org/#/docs/main/stable/typedef/PresenceData
the links shows it.
But isnt a looping required?
bc client.ws.shard is a collection of ws shards
(event) Client#shardReady
Emitted when a shard turns ready.
A question, when I just edit the status
....., without providing a shardid, will it edit it globally on the client?
All shards the client has
@next plaza
will it overwrite the current activity.name, when they are different?
Yes
So there is no possibility to make somethink like "Bot is Starting
" and then "Playing cmd | Shard 0"
Set timeout is the only way to do it
You can’t have a presence before the bot becomes ready
i mean you TECHNICALLY could if you used the websocket connection direcetly, no djs, just connect and set the status, but you should never to that tbh
So you would have to run two instances per shard
i've been stuck on the same sharding issue for days lol but im using akairo so i don't think many can help me here
state your question 
so tl;dr i'm using akairo with Kurasuta (sharding on multiple cores) and it keeps erroring after the timeout period of 30 seconds saying "Cluster 0 took too long to start", setting the timeout to -1 or Infinity does nothing. if i start the bot normally, it works fine and logs in.
worst case scenario i can just use djs' sharding but i'd rather not since Kurasuta is mutlicore
discord js sharding manager is multicore too

both do the same thing
I saw their code and they do the same thing, start worker_threads or child_processes
hm did not know that
so i guess ill use that lol
use the normal sharding manager, when your bot is over 2500 guilds. WHen your bot uses less cpu....then you can use internal sharding
Note: Sharding has no effect on bots smaller than 2k guilds
do you them as an array of objects?
So I get an error on one of my last few shards saying it's timed out
and then the rest of them don't spawn
this will give [guild1, guild2, guild3, guild4......]
updated it 
to learn? you to know?