diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index bd53a2b91033..a9e64b3e2e61 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -346,15 +346,6 @@ class Client extends BaseClient { ); this.ws.on(WebSocketShardEvents.Dispatch, this._handlePacket.bind(this)); - this.ws.on(WebSocketShardEvents.Ready, async data => { - for (const guild of data.guilds) { - this.expectedGuilds.add(guild.id); - } - - this.status = Status.WaitingForGuilds; - await this._checkReady(); - }); - this.ws.on(WebSocketShardEvents.HeartbeatComplete, ({ heartbeatAt, latency }, shardId) => { this.emit(Events.Debug, `[WS => Shard ${shardId}] Heartbeat acknowledged, latency of ${latency}ms.`); this.lastPingTimestamps.set(shardId, heartbeatAt); @@ -384,7 +375,9 @@ class Client extends BaseClient { PacketHandlers[packet.t](this, packet, shardId); } - if (this.status === Status.WaitingForGuilds && WaitingForGuildEvents.includes(packet.t)) { + if (packet.t === GatewayDispatchEvents.Ready) { + await this._checkReady(); + } else if (this.status === Status.WaitingForGuilds && WaitingForGuildEvents.includes(packet.t)) { this.expectedGuilds.delete(packet.d.id); await this._checkReady(); } diff --git a/packages/discord.js/src/client/websocket/handlers/READY.js b/packages/discord.js/src/client/websocket/handlers/READY.js index bf78a1368de6..393d832d4a79 100644 --- a/packages/discord.js/src/client/websocket/handlers/READY.js +++ b/packages/discord.js/src/client/websocket/handlers/READY.js @@ -1,6 +1,7 @@ 'use strict'; const { ClientApplication } = require('../../../structures/ClientApplication.js'); +const { Status } = require('../../../util/Status.js'); let ClientUser; @@ -14,6 +15,7 @@ module.exports = (client, { d: data }, shardId) => { } for (const guild of data.guilds) { + client.expectedGuilds.add(guild.id); guild.shardId = shardId; client.guilds._add(guild); } @@ -23,4 +25,6 @@ module.exports = (client, { d: data }, shardId) => { } else { client.application = new ClientApplication(client, data.application); } + + client.status = Status.WaitingForGuilds; };