From db6134cf95bb8ff74ca563e3f57d59f0a9b567a4 Mon Sep 17 00:00:00 2001 From: MARCROCK22 Date: Wed, 5 Jun 2024 23:34:24 +0000 Subject: [PATCH] fix: guildCreate event --- src/client/client.ts | 24 +++++++------- src/client/workerclient.ts | 66 ++++++++++++++++++++++---------------- 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/src/client/client.ts b/src/client/client.ts index 167a6c5..48902bd 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -181,7 +181,18 @@ export class Client extends BaseClient { } await this.events?.execute(packet.t, packet, this as Client, shardId); break; - + case 'GUILD_CREATE': { + if (this.__handleGuilds?.has(packet.d.id)) { + this.__handleGuilds.delete(packet.d.id); + if (!this.__handleGuilds.size && [...this.gateway.values()].every(shard => shard.data.session_id)) { + await this.events?.runEvent('BOT_READY', this, this.me, -1); + } + if (!this.__handleGuilds.size) delete this.__handleGuilds; + return; + } + await this.events?.execute(packet.t, packet, this as Client, shardId); + break; + } //rest of the events default: { await this.events?.execute(packet.t, packet, this as Client, shardId); @@ -212,17 +223,6 @@ export class Client extends BaseClient { } this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`); break; - case 'GUILD_CREATE': { - if (this.__handleGuilds?.has(packet.d.id)) { - this.__handleGuilds.delete(packet.d.id); - if (!this.__handleGuilds.size && [...this.gateway.values()].every(shard => shard.data.session_id)) { - await this.events?.runEvent('BOT_READY', this, this.me, -1); - } - if (!this.__handleGuilds.size) delete this.__handleGuilds; - return; - } - break; - } } break; } diff --git a/src/client/workerclient.ts b/src/client/workerclient.ts index 54004d5..b1f9477 100644 --- a/src/client/workerclient.ts +++ b/src/client/workerclient.ts @@ -333,35 +333,7 @@ export class WorkerClient extends BaseClient { protected async onPacket(packet: GatewayDispatchPayload, shardId: number) { await this.events?.execute('RAW', packet, this as WorkerClient, shardId); - await this.events?.execute(packet.t, packet, this, shardId); switch (packet.t) { - case 'READY': - for (const g of packet.d.guilds) { - this.__handleGuilds?.add(g.id); - } - this.botId = packet.d.user.id; - this.applicationId = packet.d.application.id; - this.me = new ClientUser(this, packet.d.user, packet.d.application) as never; - if ( - !(this.__handleGuilds?.size && (workerData.intents & GatewayIntentBits.Guilds) === GatewayIntentBits.Guilds) - ) { - if ([...this.shards.values()].every(shard => shard.data.session_id)) { - this.postMessage({ - type: 'WORKER_READY', - workerId: this.workerId, - } as WorkerReady); - await this.events?.runEvent('WORKER_READY', this, this.me, -1); - } - delete this.__handleGuilds; - } - this.debugger?.debug(`#${shardId} [${packet.d.user.username}](${this.botId}) is online...`); - break; - case 'INTERACTION_CREATE': - await onInteractionCreate(this, packet.d, shardId); - break; - case 'MESSAGE_CREATE': - await onMessageCreate(this, packet.d, shardId); - break; case 'GUILD_CREATE': { if (this.__handleGuilds?.has(packet.d.id)) { this.__handleGuilds.delete(packet.d.id); @@ -375,6 +347,44 @@ export class WorkerClient extends BaseClient { if (!this.__handleGuilds.size) delete this.__handleGuilds; return; } + await this.events?.execute(packet.t, packet, this, shardId); + break; + } + default: { + await this.events?.execute(packet.t, packet, this, shardId); + switch (packet.t) { + case 'READY': + for (const g of packet.d.guilds) { + this.__handleGuilds?.add(g.id); + } + this.botId = packet.d.user.id; + this.applicationId = packet.d.application.id; + this.me = new ClientUser(this, packet.d.user, packet.d.application) as never; + if ( + !( + this.__handleGuilds?.size && + (workerData.intents & GatewayIntentBits.Guilds) === GatewayIntentBits.Guilds + ) + ) { + if ([...this.shards.values()].every(shard => shard.data.session_id)) { + this.postMessage({ + type: 'WORKER_READY', + workerId: this.workerId, + } as WorkerReady); + await this.events?.runEvent('WORKER_READY', this, this.me, -1); + } + delete this.__handleGuilds; + } + this.debugger?.debug(`#${shardId} [${packet.d.user.username}](${this.botId}) is online...`); + break; + case 'INTERACTION_CREATE': + await onInteractionCreate(this, packet.d, shardId); + break; + case 'MESSAGE_CREATE': + await onMessageCreate(this, packet.d, shardId); + break; + } + break; } } }