Sharding questions.

Hi. I am building a Discord bot which I can anticipate will eventually be in more than 2500 guilds pretty quick. I have a few questions about sharding which I am looking to have answered, any help is greatly appreciated: 1. Is it best to prepare and set up sharding for the bot now while I can? 2. Once the sharding manager is created, do I have to go back into my code (such as commands) and change it to work with all shards? Or does that depend on if the command should affect other guilds, for example? 3. What are the main use cases for using commands such as .broadcastEval() to communicate to all shards? Thanks!
11 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
duck
duck2mo ago
I'd say this all depends entirely on what you're doing
Or does that depend on if the command should affect other guilds, for example?
this is the right idea or rather, if there are any features that affect or are affected by other shards e.g. all DMs are sent to shard 0, so while you might be able to send a DM containing components from any shard (since that's via REST), you may encounter issues attempting to use a collector afterwards therefore depending on what you're doing, it may take no time at all or a lengthy amount of time to refactor for sharding with that in mind 1. depends on how fast "pretty quick" is and how fast you expect to be able to refactor for sharding also depends on whether you could also consider using internal sharding (passing shards: "auto" in the Client options) instead of the ShardingManager if you really feel you wouldn't be able to refactor for a ShardingManager before your bot joins too many guilds, you're free to set things up whenever you like, but our guide recommends beginning to think about it at around 2000 guilds 3. there isn't really a "main use case" beyond communicating between shards our guide has examples for polling total guild/member counts across all shards with broadcastEval, but it can be used for a wide variety of things if you have a more specific situation or feature of your bot you'd like to describe and ask a question about, feel free to do so
Swyftey
SwyfteyOP2mo ago
Thank you! My bot is going to be an “invite bot”, similar to services such as disboard. I’m not sure I understand the shards: ‘auto’ option. Would this be okay to use for my case? Edit: I think I’m understanding that it automatically scales your shards based on the number of guilds, but is that okay to use for an invite bot? I just want to make sure I am prepared so that when my website goes live, I won’t run into any issues.
duck
duck2mo ago
My bot is going to be an “invite bot”, similar to services such as disboard.
that isn't exactly a specific situation or feature, so hard to really give a specific answer on how traditional sharding may affect this especially since (while I've heard of it) I don't know what disboard actually is researching it now, this appears to be a website that does not have a bot (it has an oauth app and therefore doesn't require a gateway connection), so frankly that just raises more questions; but to clarify, I meant that if you have something specific in your code or a specific situation your bot will encounter while being utilized that you're unsure about, feel free to ask about that
I’m not sure I understand the shards: ‘auto’ option. Would this be okay to use for my case?
to fully elaborate, both internal sharding and traditional sharding automatically scale your shards based on number of guilds unless you specify otherwise discord already handles providing a recommended shard count internal sharding is an alternative to the ShardingManager that simply creates multiple connections to the gateway internally to one Client in one process this one Client would handle all caching, so this would require no refactoring on your part in exchange for escalated resource usage by this one process as mentioned on our guide, internal sharding should be temporary and eventually replaced by traditional sharding, as a larger bot would have absolutely incredible resource usage that genuinely should be divided up which is to say, this is effectively just a means of putting off refactoring for a different sharding system therefore the choice to use this instead of the ShardingManager depends more on you, your host, and the environment your bot will be running in
I just want to make sure I am prepared so that when my website goes live, I won’t run into any issues.
again, our guide recommends beginning to think about it around 2000 guilds if you really think your bot will join 2500 guilds instantaneously when your website goes live (or even just so quick you couldn't refactor in time), feel free to set things up now, but if not, this sounds like unnecessary resource usage that's great you're free to read any info here similarly, if you have a more specific situation or feature of your bot you'd like to describe and ask a question about, feel free to open your own post no thank you feel free to open your own post
Swyftey
SwyfteyOP2mo ago
Thank you! Disboard does have a bot. I want to say for any Discord server that is actively being promoted on their website, their Discord bot is in that server. The bot is used to connect to each server, for the server owners (or members) to use simple commands such as "bump" to bump the server on their website or add a server via a command (something like that maybe).
duck
duck2mo ago
this is still aside from the point
I meant that if you have something specific in your code or a specific situation your bot will encounter while being utilized that you're unsure about, feel free to ask about that
Swyftey
SwyfteyOP2mo ago
Alright. But I guess I'm just still a little bit confused confused. If I decide to just make the sharding manager now to get it over with, should I just go with 'traditional sharding'?
duck
duck2mo ago
it's really up to you
Swyftey
SwyfteyOP2mo ago
Alright I guess my last question is what exactly is traditional sharding lol how do you go about it* But, I am using the sharding manager this is what I have so far
Swyftey
SwyfteyOP2mo ago
No description
Swyftey
SwyfteyOP2mo ago
even with the 'totalShards' to 'auto'? Ok I see what the internal sharding means from what duck said It worked I’m using deno Also thank you Sorry, one more question I can think of. So, the shards will be created automatically based on the number of guilds. Do I need to worry about my hardware (the VPS) at all to make sure I have enough processing power or anything? Also, is there any specific settings I should worry about also related to performance? Gotcha. Thank you.
Want results from more Discord servers?
Add your server