From f95f8cc0a3ce6b88319d9e7bd71e9b5b39d3de86 Mon Sep 17 00:00:00 2001 From: ckohen Date: Mon, 2 Aug 2021 17:26:42 -0700 Subject: [PATCH 1/2] fix(WebSocketShard): mark shard ready if no guilds intent --- src/client/websocket/WebSocketShard.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/client/websocket/WebSocketShard.js b/src/client/websocket/WebSocketShard.js index ab5b9216411d..02083a3ac6d6 100644 --- a/src/client/websocket/WebSocketShard.js +++ b/src/client/websocket/WebSocketShard.js @@ -474,17 +474,23 @@ class WebSocketShard extends EventEmitter { this.emit(ShardEvents.ALL_READY); return; } + let time = 15000; + if (!new Intents(this.manager.client.options.intents).has(Intents.FLAGS.GUILDS)) { + time = 0; + } // Step 2. Create a 15s timeout that will mark the shard as ready if there are still unavailable guilds this.readyTimeout = setTimeout(() => { - this.debug(`Shard did not receive any more guild packets in 15 seconds. - Unavailable guild count: ${this.expectedGuilds.size}`); + this.debug( + `Shard ${time === 0 ? 'will' : 'did'} not receive any more guild packets` + + `${time === 0 ? '' : ' in 15 seconds'}.\n Unavailable guild count: ${this.expectedGuilds.size}`, + ); this.readyTimeout = null; this.status = Status.READY; this.emit(ShardEvents.ALL_READY, this.expectedGuilds); - }, 15000).unref(); + }, time).unref(); } /** From 17d0ced0eafa4fbf60a0d04e939b89afa9601ca3 Mon Sep 17 00:00:00 2001 From: ckohen Date: Mon, 2 Aug 2021 21:19:53 -0700 Subject: [PATCH 2/2] refactor(WebSocketShard): store intent state not time Co-Authored-By: Sugden <28943913+NotSugden@users.noreply.github.com> --- src/client/websocket/WebSocketShard.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/client/websocket/WebSocketShard.js b/src/client/websocket/WebSocketShard.js index 02083a3ac6d6..25f66bbfc4f2 100644 --- a/src/client/websocket/WebSocketShard.js +++ b/src/client/websocket/WebSocketShard.js @@ -474,23 +474,23 @@ class WebSocketShard extends EventEmitter { this.emit(ShardEvents.ALL_READY); return; } - let time = 15000; - if (!new Intents(this.manager.client.options.intents).has(Intents.FLAGS.GUILDS)) { - time = 0; - } + const hasGuildsIntent = new Intents(this.manager.client.options.intents).has(Intents.FLAGS.GUILDS); // Step 2. Create a 15s timeout that will mark the shard as ready if there are still unavailable guilds - this.readyTimeout = setTimeout(() => { - this.debug( - `Shard ${time === 0 ? 'will' : 'did'} not receive any more guild packets` + - `${time === 0 ? '' : ' in 15 seconds'}.\n Unavailable guild count: ${this.expectedGuilds.size}`, - ); + this.readyTimeout = setTimeout( + () => { + this.debug( + `Shard ${hasGuildsIntent ? 'did' : 'will'} not receive any more guild packets` + + `${hasGuildsIntent ? ' in 15 seconds' : ''}.\n Unavailable guild count: ${this.expectedGuilds.size}`, + ); - this.readyTimeout = null; + this.readyTimeout = null; - this.status = Status.READY; + this.status = Status.READY; - this.emit(ShardEvents.ALL_READY, this.expectedGuilds); - }, time).unref(); + this.emit(ShardEvents.ALL_READY, this.expectedGuilds); + }, + hasGuildsIntent ? 15000 : 0, + ).unref(); } /**