From 91bf30e4b3f436cfa6119988bd95dc317442bd99 Mon Sep 17 00:00:00 2001 From: Fabrizio Santana <74118796+FabrizioCoder@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:54:23 -0600 Subject: [PATCH] Fixes (#231) * fix: event handling in client.ts and workerclient.ts * fix: optional --- src/client/client.ts | 10 +++++----- src/client/workerclient.ts | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/client/client.ts b/src/client/client.ts index d222fc9..3724042 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -159,11 +159,11 @@ export class Client extends BaseClient { 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)) { + 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; + if (!this.__handleGuilds?.size) delete this.__handleGuilds; return this.cache.onPacket(packet); } await this.events?.execute(packet.t, packet, this as Client, shardId); @@ -183,7 +183,7 @@ export class Client extends BaseClient { case 'READY': if (!this.__handleGuilds) this.__handleGuilds = new Set(); for (const g of packet.d.guilds) { - this.__handleGuilds.add(g.id); + this.__handleGuilds?.add(g.id); } await this.events?.execute(packet.t as never, packet, this as Client, shardId); this.botId = packet.d.user.id; @@ -191,7 +191,7 @@ export class Client extends BaseClient { this.me = Transformers.ClientUser(this, packet.d.user, packet.d.application) as never; if ( !( - this.__handleGuilds.size && + this.__handleGuilds?.size && (this.gateway.options.intents & GatewayIntentBits.Guilds) === GatewayIntentBits.Guilds ) ) { diff --git a/src/client/workerclient.ts b/src/client/workerclient.ts index fe6d136..60341f1 100644 --- a/src/client/workerclient.ts +++ b/src/client/workerclient.ts @@ -365,15 +365,15 @@ export class WorkerClient extends BaseClient { break; case 'GUILD_CREATE': { if (this.__handleGuilds?.has(packet.d.id)) { - this.__handleGuilds.delete(packet.d.id); - if (!this.__handleGuilds.size && [...this.shards.values()].every(shard => shard.data.session_id)) { + this.__handleGuilds?.delete(packet.d.id); + if (!this.__handleGuilds?.size && [...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); } - if (!this.__handleGuilds.size) delete this.__handleGuilds; + if (!this.__handleGuilds?.size) delete this.__handleGuilds; return this.cache.onPacket(packet); } await this.events?.execute(packet.t, packet, this, shardId); @@ -392,7 +392,7 @@ export class WorkerClient extends BaseClient { case 'READY': if (!this.__handleGuilds) this.__handleGuilds = new Set(); for (const g of packet.d.guilds) { - this.__handleGuilds.add(g.id); + this.__handleGuilds?.add(g.id); } await this.events?.execute(packet.t as never, packet, this, shardId); this.botId = packet.d.user.id; @@ -400,7 +400,8 @@ export class WorkerClient extends BaseClient { this.me = Transformers.ClientUser(this, packet.d.user, packet.d.application) as never; if ( !( - this.__handleGuilds.size && (workerData.intents & GatewayIntentBits.Guilds) === GatewayIntentBits.Guilds + this.__handleGuilds?.size && + (workerData.intents & GatewayIntentBits.Guilds) === GatewayIntentBits.Guilds ) ) { if ([...this.shards.values()].every(shard => shard.data.session_id)) {