mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(Client): Move client initialization code (#11184)
* Update index.js * Fix * Fix path to ClientUser * Update Client.js * Migrating back to READY.js * Move _checkReady() --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: Denis-Adrian Cristea <didinele.dev@gmail.com>
This commit is contained in:
@@ -389,15 +389,6 @@ class Client extends AsyncEventEmitter {
|
||||
);
|
||||
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);
|
||||
@@ -427,7 +418,9 @@ class Client extends AsyncEventEmitter {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user