shay
shay
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by shay on 7/11/2024 in #djs-questions
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
21 replies