From c16942f6a2bb11c22f8f67e898847b9e9719fb8e Mon Sep 17 00:00:00 2001 From: VAKiliner <119078586+vakiliner@users.noreply.github.com> Date: Thu, 16 Oct 2025 13:58:48 +0300 Subject: [PATCH 1/6] Update index.js --- packages/discord.js/src/client/websocket/handlers/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/discord.js/src/client/websocket/handlers/index.js b/packages/discord.js/src/client/websocket/handlers/index.js index 148bcd729faf..24799377893a 100644 --- a/packages/discord.js/src/client/websocket/handlers/index.js +++ b/packages/discord.js/src/client/websocket/handlers/index.js @@ -52,7 +52,6 @@ const PacketHandlers = Object.fromEntries([ ['MESSAGE_REACTION_REMOVE_EMOJI', require('./MESSAGE_REACTION_REMOVE_EMOJI.js')], ['MESSAGE_UPDATE', require('./MESSAGE_UPDATE.js')], ['PRESENCE_UPDATE', require('./PRESENCE_UPDATE.js')], - ['READY', require('./READY.js')], ['SOUNDBOARD_SOUNDS', require('./SOUNDBOARD_SOUNDS.js')], ['STAGE_INSTANCE_CREATE', require('./STAGE_INSTANCE_CREATE.js')], ['STAGE_INSTANCE_DELETE', require('./STAGE_INSTANCE_DELETE.js')], From ce7facb71e1a16e3642cb842667d4cf241083b83 Mon Sep 17 00:00:00 2001 From: VAKiliner Date: Thu, 16 Oct 2025 14:02:18 +0300 Subject: [PATCH 2/6] Fix --- packages/discord.js/src/client/Client.js | 19 ++++++++++++++ .../src/client/websocket/handlers/READY.js | 26 ------------------- 2 files changed, 19 insertions(+), 26 deletions(-) delete mode 100644 packages/discord.js/src/client/websocket/handlers/READY.js diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index bd53a2b91033..fb159a456c42 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -32,6 +32,7 @@ const { BaseClient } = require('./BaseClient.js'); const { ActionsManager } = require('./actions/ActionsManager.js'); const { ClientVoiceManager } = require('./voice/ClientVoiceManager.js'); const { PacketHandlers } = require('./websocket/handlers/index.js'); +const { ClientApplication } = require('../structures/ClientApplication.js'); const WaitingForGuildEvents = [GatewayDispatchEvents.GuildCreate, GatewayDispatchEvents.GuildDelete]; const BeforeReadyWhitelist = [ @@ -44,6 +45,8 @@ const BeforeReadyWhitelist = [ GatewayDispatchEvents.GuildMemberRemove, ]; +let ClientUser; + /** * The main hub for interacting with the Discord API, and the starting point for any bot. * @@ -347,8 +350,24 @@ class Client extends BaseClient { this.ws.on(WebSocketShardEvents.Dispatch, this._handlePacket.bind(this)); this.ws.on(WebSocketShardEvents.Ready, async data => { + if (this.user) { + this.user._patch(data.user); + } else { + ClientUser ??= require('../../../structures/ClientUser.js').ClientUser; + this.user = new ClientUser(this, data.user); + this.users.cache.set(this.user.id, this.user); + } + for (const guild of data.guilds) { this.expectedGuilds.add(guild.id); + guild.shardId = shardId; + this.guilds._add(guild); + } + + if (this.application) { + this.application._patch(data.application); + } else { + this.application = new ClientApplication(this, data.application); } this.status = Status.WaitingForGuilds; diff --git a/packages/discord.js/src/client/websocket/handlers/READY.js b/packages/discord.js/src/client/websocket/handlers/READY.js deleted file mode 100644 index bf78a1368de6..000000000000 --- a/packages/discord.js/src/client/websocket/handlers/READY.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -const { ClientApplication } = require('../../../structures/ClientApplication.js'); - -let ClientUser; - -module.exports = (client, { d: data }, shardId) => { - if (client.user) { - client.user._patch(data.user); - } else { - ClientUser ??= require('../../../structures/ClientUser.js').ClientUser; - client.user = new ClientUser(client, data.user); - client.users.cache.set(client.user.id, client.user); - } - - for (const guild of data.guilds) { - guild.shardId = shardId; - client.guilds._add(guild); - } - - if (client.application) { - client.application._patch(data.application); - } else { - client.application = new ClientApplication(client, data.application); - } -}; From 382f331493b5755bcfff7adc96a24321cb7c220d Mon Sep 17 00:00:00 2001 From: VAKiliner Date: Thu, 16 Oct 2025 16:34:57 +0300 Subject: [PATCH 3/6] Fix path to ClientUser --- packages/discord.js/src/client/Client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index fb159a456c42..7513fab06175 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -353,7 +353,7 @@ class Client extends BaseClient { if (this.user) { this.user._patch(data.user); } else { - ClientUser ??= require('../../../structures/ClientUser.js').ClientUser; + ClientUser ??= require('../structures/ClientUser.js').ClientUser; this.user = new ClientUser(this, data.user); this.users.cache.set(this.user.id, this.user); } From 3b16e5f96aa3c08b7d0acaed78c42c59bbb1d0cf Mon Sep 17 00:00:00 2001 From: VAKiliner Date: Thu, 16 Oct 2025 17:06:58 +0300 Subject: [PATCH 4/6] Update Client.js --- packages/discord.js/src/client/Client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index 7513fab06175..51748082f64a 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -11,6 +11,7 @@ const { ChannelManager } = require('../managers/ChannelManager.js'); const { GuildManager } = require('../managers/GuildManager.js'); const { UserManager } = require('../managers/UserManager.js'); const { ShardClientUtil } = require('../sharding/ShardClientUtil.js'); +const { ClientApplication } = require('../structures/ClientApplication.js'); const { ClientPresence } = require('../structures/ClientPresence.js'); const { GuildPreview } = require('../structures/GuildPreview.js'); const { GuildTemplate } = require('../structures/GuildTemplate.js'); @@ -32,7 +33,6 @@ const { BaseClient } = require('./BaseClient.js'); const { ActionsManager } = require('./actions/ActionsManager.js'); const { ClientVoiceManager } = require('./voice/ClientVoiceManager.js'); const { PacketHandlers } = require('./websocket/handlers/index.js'); -const { ClientApplication } = require('../structures/ClientApplication.js'); const WaitingForGuildEvents = [GatewayDispatchEvents.GuildCreate, GatewayDispatchEvents.GuildDelete]; const BeforeReadyWhitelist = [ @@ -349,7 +349,7 @@ class Client extends BaseClient { ); this.ws.on(WebSocketShardEvents.Dispatch, this._handlePacket.bind(this)); - this.ws.on(WebSocketShardEvents.Ready, async data => { + this.ws.on(WebSocketShardEvents.Ready, async (data, shardId) => { if (this.user) { this.user._patch(data.user); } else { From 4ab11b158e086509dfb514c907342442242f1ba9 Mon Sep 17 00:00:00 2001 From: VAKiliner Date: Sun, 19 Oct 2025 18:59:09 +0300 Subject: [PATCH 5/6] Migrating back to READY.js --- packages/discord.js/src/client/Client.js | 30 +----------------- .../src/client/websocket/handlers/READY.js | 31 +++++++++++++++++++ .../src/client/websocket/handlers/index.js | 1 + 3 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 packages/discord.js/src/client/websocket/handlers/READY.js diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index 51748082f64a..344c735635c1 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -11,7 +11,6 @@ const { ChannelManager } = require('../managers/ChannelManager.js'); const { GuildManager } = require('../managers/GuildManager.js'); const { UserManager } = require('../managers/UserManager.js'); const { ShardClientUtil } = require('../sharding/ShardClientUtil.js'); -const { ClientApplication } = require('../structures/ClientApplication.js'); const { ClientPresence } = require('../structures/ClientPresence.js'); const { GuildPreview } = require('../structures/GuildPreview.js'); const { GuildTemplate } = require('../structures/GuildTemplate.js'); @@ -45,8 +44,6 @@ const BeforeReadyWhitelist = [ GatewayDispatchEvents.GuildMemberRemove, ]; -let ClientUser; - /** * The main hub for interacting with the Discord API, and the starting point for any bot. * @@ -349,31 +346,6 @@ class Client extends BaseClient { ); this.ws.on(WebSocketShardEvents.Dispatch, this._handlePacket.bind(this)); - this.ws.on(WebSocketShardEvents.Ready, async (data, shardId) => { - if (this.user) { - this.user._patch(data.user); - } else { - ClientUser ??= require('../structures/ClientUser.js').ClientUser; - this.user = new ClientUser(this, data.user); - this.users.cache.set(this.user.id, this.user); - } - - for (const guild of data.guilds) { - this.expectedGuilds.add(guild.id); - guild.shardId = shardId; - this.guilds._add(guild); - } - - if (this.application) { - this.application._patch(data.application); - } else { - this.application = new ClientApplication(this, data.application); - } - - 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); @@ -400,7 +372,7 @@ class Client extends BaseClient { } if (PacketHandlers[packet.t]) { - PacketHandlers[packet.t](this, packet, shardId); + await PacketHandlers[packet.t](this, packet, shardId); } if (this.status === Status.WaitingForGuilds && WaitingForGuildEvents.includes(packet.t)) { diff --git a/packages/discord.js/src/client/websocket/handlers/READY.js b/packages/discord.js/src/client/websocket/handlers/READY.js new file mode 100644 index 000000000000..ff148c3959b2 --- /dev/null +++ b/packages/discord.js/src/client/websocket/handlers/READY.js @@ -0,0 +1,31 @@ +'use strict'; + +const { ClientApplication } = require('../../../structures/ClientApplication.js'); +const { Status } = require('../../../util/Status.js'); + +let ClientUser; + +module.exports = async (client, { d: data }, shardId) => { + if (client.user) { + client.user._patch(data.user); + } else { + ClientUser ??= require('../../../structures/ClientUser.js').ClientUser; + client.user = new ClientUser(client, data.user); + client.users.cache.set(client.user.id, client.user); + } + + for (const guild of data.guilds) { + client.expectedGuilds.add(guild.id); + guild.shardId = shardId; + client.guilds._add(guild); + } + + if (client.application) { + client.application._patch(data.application); + } else { + client.application = new ClientApplication(client, data.application); + } + + client.status = Status.WaitingForGuilds; + await client._checkReady(); +}; diff --git a/packages/discord.js/src/client/websocket/handlers/index.js b/packages/discord.js/src/client/websocket/handlers/index.js index 24799377893a..148bcd729faf 100644 --- a/packages/discord.js/src/client/websocket/handlers/index.js +++ b/packages/discord.js/src/client/websocket/handlers/index.js @@ -52,6 +52,7 @@ const PacketHandlers = Object.fromEntries([ ['MESSAGE_REACTION_REMOVE_EMOJI', require('./MESSAGE_REACTION_REMOVE_EMOJI.js')], ['MESSAGE_UPDATE', require('./MESSAGE_UPDATE.js')], ['PRESENCE_UPDATE', require('./PRESENCE_UPDATE.js')], + ['READY', require('./READY.js')], ['SOUNDBOARD_SOUNDS', require('./SOUNDBOARD_SOUNDS.js')], ['STAGE_INSTANCE_CREATE', require('./STAGE_INSTANCE_CREATE.js')], ['STAGE_INSTANCE_DELETE', require('./STAGE_INSTANCE_DELETE.js')], From a4c0a246f0264ffb550abd413bc3920d7d24b979 Mon Sep 17 00:00:00 2001 From: VAKiliner Date: Sun, 19 Oct 2025 20:39:16 +0300 Subject: [PATCH 6/6] Move _checkReady() --- packages/discord.js/src/client/Client.js | 6 ++++-- packages/discord.js/src/client/websocket/handlers/READY.js | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index 344c735635c1..a9e64b3e2e61 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -372,10 +372,12 @@ class Client extends BaseClient { } if (PacketHandlers[packet.t]) { - await PacketHandlers[packet.t](this, packet, shardId); + 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 ff148c3959b2..393d832d4a79 100644 --- a/packages/discord.js/src/client/websocket/handlers/READY.js +++ b/packages/discord.js/src/client/websocket/handlers/READY.js @@ -5,7 +5,7 @@ const { Status } = require('../../../util/Status.js'); let ClientUser; -module.exports = async (client, { d: data }, shardId) => { +module.exports = (client, { d: data }, shardId) => { if (client.user) { client.user._patch(data.user); } else { @@ -27,5 +27,4 @@ module.exports = async (client, { d: data }, shardId) => { } client.status = Status.WaitingForGuilds; - await client._checkReady(); };