Non-internal sharding without using a full `Client` instance

Hi there, I own a large bot that I'm rewriting to be mostly HTTP-based. However, there are a number of features that require a gateway connection, so I am going to be running a discord.js application alongside it which will proxy events to the HTTP server (the latency introduced with this method is not a big concern). I have written the gateway-enabled bot portion with @discordjs/rest and @discordjs/ws in order to minimize ram usage. Unfortunately it seems that ShardingManager requires you to use a full-fat Client instance, which I don't want to do because of the limited cache reduction options - I do not need any cache, only an array of guild IDs for each shard, which I am currently tracking myself.
% node src/index.js
[launched] Shard ID 0
[hello] Shard ID 0
ready with 1 shards on 2 guilds
/Users/shay/Documents/GitHub/project/packages/bot-ws/node_modules/discord.js/src/sharding/Shard.js:183
reject(new DiscordjsError(ErrorCodes.ShardingReadyTimeout, this.id));
^

Error [ShardingReadyTimeout]: Shard 0's Client took too long to become ready.
at Timeout.onTimeout (/Users/shay/Documents/GitHub/project/packages/bot-ws/node_modules/discord.js/src/sharding/Shard.js:183:16)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7) {
code: 'ShardingReadyTimeout'
}
% node src/index.js
[launched] Shard ID 0
[hello] Shard ID 0
ready with 1 shards on 2 guilds
/Users/shay/Documents/GitHub/project/packages/bot-ws/node_modules/discord.js/src/sharding/Shard.js:183
reject(new DiscordjsError(ErrorCodes.ShardingReadyTimeout, this.id));
^

Error [ShardingReadyTimeout]: Shard 0's Client took too long to become ready.
at Timeout.onTimeout (/Users/shay/Documents/GitHub/project/packages/bot-ws/node_modules/discord.js/src/sharding/Shard.js:183:16)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7) {
code: 'ShardingReadyTimeout'
}
^ the ready with [...] log there is from my WebSocketManager#on WebSocketShardEvents.Ready callback. The manager is ready but it seems like the parent ShardManager expects a Client instead. Is there any way to maintain my desired philosophy? Thanks discord.js 14.15.3 @discordjs/rest 2.3.0 @discordjs/ws 1.1.1 node 21.6.2
14 Replies
d.js toolkit
d.js toolkit6mo 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!
Kinect3000
Kinect30006mo ago
WebsocketManager doesn’t use Client
Kinect3000
Kinect30006mo ago
The point of the sub modules is to factor out d.js, not for it to depend on d.js
shay
shayOP6mo ago
Yeah, but it doesn't seem like I can use ShardingManager without installing d.js so I guess a better form of my question would be, how can I shard like this without installing d.js proper
Kinect3000
Kinect30006mo ago
Why not? Do you get an error or smth?
shay
shayOP6mo ago
because ShardingManager is only in d.js proper?
Kinect3000
Kinect30006mo ago
No
shay
shayOP6mo ago
I couldn't find the submodule it was a member of, what's it from?
Kinect3000
Kinect30006mo ago
@discordjs/ws The one I linked you to above The ws sub package handles ws connections and shards
shay
shayOP6mo ago
oh, is WebSocketManager able to shard non-internally? I thought I needed an external manager process
Kinect3000
Kinect30006mo ago
Oh right, it defaults to the worker threads strategy You would need to make a strategy for spawning shards across processes. It is overridable in the options.buildStrategy
shay
shayOP6mo ago
ok, thanks for the help if I mark this as solved am I still able to come back later and post what I end up writing or will it be locked?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server