fix: guildCreate event

This commit is contained in:
MARCROCK22 2024-06-05 23:34:24 +00:00
parent 23be553844
commit db6134cf95
2 changed files with 50 additions and 40 deletions

View File

@ -181,7 +181,18 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
} }
await this.events?.execute(packet.t, packet, this as Client<true>, shardId); await this.events?.execute(packet.t, packet, this as Client<true>, shardId);
break; 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<true>, shardId);
break;
}
//rest of the events //rest of the events
default: { default: {
await this.events?.execute(packet.t, packet, this as Client<true>, shardId); await this.events?.execute(packet.t, packet, this as Client<true>, shardId);
@ -212,17 +223,6 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
} }
this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`); this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
break; 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; break;
} }

View File

@ -333,6 +333,24 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
protected async onPacket(packet: GatewayDispatchPayload, shardId: number) { protected async onPacket(packet: GatewayDispatchPayload, shardId: number) {
await this.events?.execute('RAW', packet, this as WorkerClient<true>, shardId); await this.events?.execute('RAW', packet, this as WorkerClient<true>, shardId);
switch (packet.t) {
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.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;
return;
}
await this.events?.execute(packet.t, packet, this, shardId);
break;
}
default: {
await this.events?.execute(packet.t, packet, this, shardId); await this.events?.execute(packet.t, packet, this, shardId);
switch (packet.t) { switch (packet.t) {
case 'READY': case 'READY':
@ -343,7 +361,10 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
this.applicationId = packet.d.application.id; this.applicationId = packet.d.application.id;
this.me = new ClientUser(this, packet.d.user, packet.d.application) as never; this.me = new ClientUser(this, packet.d.user, packet.d.application) as never;
if ( 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)) { if ([...this.shards.values()].every(shard => shard.data.session_id)) {
this.postMessage({ this.postMessage({
@ -362,19 +383,8 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
case 'MESSAGE_CREATE': case 'MESSAGE_CREATE':
await onMessageCreate(this, packet.d, shardId); await onMessageCreate(this, packet.d, shardId);
break; 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.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;
return;
} }
break;
} }
} }
} }