Issue with @discordjs/ws sharding
I am trying to use worker threads for sharding just like shown in the docs just in common js instead ts https://discordjs.dev/docs/packages/ws/main
This is the code:
Why do I get this error?
52 Replies
- 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!
- ✅
Marked as resolved by OPCoreVoice@ C:\Users\Jonah\Github\CoreVoice
├── @discordjs/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
from what i can see, they did not pass rest on the constructor
try passing rest and retry
How to do this in that case? The docs didnt showed it
simply add rest after token
you should have no need for the unknown payload handler so you can safely omit it, the same goes for workerpath
im sorry what version of /ws and /rest do you have?
^^
can you try omitting
fetchGatewayInformation()
and retry this?
/ws /rest is not listed there
do you have it seperately installed?Oh I see
fetchGatewayInformation is in no stable release
I use them from discordjs/core
so there is no way you can access it from a stable release
so you must have a dev version installed
can you omit fetchGatewayInformation() ?
and retry running it
sec
If I omit it there seems to be no error in console
that is expected behaviour
fetchGatewayInformation is in no stable release of /ws
did you omit workerPath as well?
unless you have a custom bootstrapper, you should not need it
workerPath is still inside
alright I will omit it too
are you trying to build a microservice with this? or are you trying to use it with discordjs/core?
Trying to use it with discordjs/core to implement sharding instead of using a package called discord-hybrid-sharing
https://discord.js.org/docs/packages/core/main provides an example on how to use /ws with it
discord.js
discord.js
discord.js is a powerful Node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
discord-hybrid-sharing shards via internal shards and worker threads to I thought using /ws would be the more native way
you can achieve sharding with workers even with mainlib
Where is the example? 😅
scroll down to example usage
Yeah that in that way I already use it but it doesnt show how to use sharding from /ws
Its for a kinda bigger bot in 160k guilds
did you pass buildStrategy?
No, do I just have to do this?
passing this should be sufficient yes
oh
I see
or you can cram all shards in one thread by passing "all" to shardsperworker
if that is what you want
:shruggiesrainbowcat:
it is all up to the consumer
Ah, yes. this should not be something you need and by general, it is considered bad practice, please excuse me for the unnecessary suggestion :bow:
shards per worker being 2 is a sweet spot for that guild count
Thats how discord-hyprid-sharding works
So I guess that the way i have to go
that is how it would work yes
shardCount can be set to null
if you want discord to handle it
I will try it out
how many shards do you have?
I am currently rewriting from discord.js to fully @discordjs/core but the shardcount will be the same
So I will need around 176
because of large bot sharding I tought that 16 shards per worker would be fine
👍
have you acquired a max concurrency of 16?
The rewrite has been fun so far. Learned a lot new stuff and noticed how much work the mainlib took over for me
Yes
:LGJ_clap:
I didnt noticed any difference when Discord send me an DM that the bot reached 150k and will now use large sharding
the process is automatic
yea
max concurrency means how many shards can initialize every 5 seconds
which in this case, is 16 for you
ohhhh
Thanks for telling me
so your bot should boot up faster now
of course :nodnod:
Well I didnt messured the time before
currently it takes at least 15min to fully start
with mainlib?
Yes
and discord-hybrid-sharding
i see
how many shards did you have again?
176
re the docs, pay attention to the version you're looking at
main is the default and we just merged a PR that makes it so ws doesn't take a REST instance anymore
Another question from my side
There wont be no broadCastEval so how could I get infos from every shard?
Yeah exacly but currently its still using something like client.guilds = new Map() per shard and not a central location like a redis
Ah I assumed its similar to the sharding of the mainlib which inizializes a client per shards and thats by broadcasteval is needed to run code on all shards
no, broadcastEval is a pretty bad pattern overall that will hopefully be getting phased out in the future
ideally you should find your own way of centralizing data
Yeah I am definitely smarter now then before I started the thread. I will try around to see how far I come now with the sharding of ws
Do I have to note anything when using this typ of sharding?
I am still not really sure how this process works and I am only familiar with the mainlib sharding and the documentation isn’t telling me much 😅
Unfortunately no one has made a guide for it to explain it further