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);
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
default: {
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...`);
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;
}

View File

@ -333,35 +333,7 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
protected async onPacket(packet: GatewayDispatchPayload, shardId: number) {
await this.events?.execute('RAW', packet, this as WorkerClient<true>, 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<Ready extends boolean = boolean> 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;
}
}
}