fix: event handling in client.ts and workerclient.ts (#230)

This commit is contained in:
Fabrizio Santana 2024-08-01 19:34:12 -06:00 committed by GitHub
parent 5e4a7e2792
commit aeae6f0e37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -171,12 +171,13 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
}
//rest of the events
default: {
await this.events?.execute(packet.t as never, packet, this as Client<true>, shardId);
switch (packet.t) {
case 'INTERACTION_CREATE':
await this.events?.execute(packet.t as never, packet, this as Client<true>, shardId);
await this.handleCommand.interaction(packet.d, shardId);
break;
case 'MESSAGE_CREATE':
await this.events?.execute(packet.t as never, packet, this as Client<true>, shardId);
await this.handleCommand.message(packet.d, shardId);
break;
case 'READY':
@ -184,6 +185,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
for (const g of packet.d.guilds) {
this.__handleGuilds.add(g.id);
}
await this.events?.execute(packet.t as never, packet, this as Client<true>, shardId);
this.botId = packet.d.user.id;
this.applicationId = packet.d.application.id;
this.me = Transformers.ClientUser(this, packet.d.user, packet.d.application) as never;
@ -200,6 +202,9 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
}
this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
break;
default:
await this.events?.execute(packet.t as never, packet, this as Client<true>, shardId);
break;
}
break;
}

View File

@ -380,12 +380,13 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
break;
}
default: {
await this.events?.execute(packet.t as never, packet, this, shardId);
switch (packet.t) {
case 'INTERACTION_CREATE':
await this.events?.execute(packet.t as never, packet, this, shardId);
await this.handleCommand.interaction(packet.d, shardId);
break;
case 'MESSAGE_CREATE':
await this.events?.execute(packet.t as never, packet, this, shardId);
await this.handleCommand.message(packet.d, shardId);
break;
case 'READY':
@ -393,6 +394,7 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
for (const g of packet.d.guilds) {
this.__handleGuilds.add(g.id);
}
await this.events?.execute(packet.t as never, packet, this, shardId);
this.botId = packet.d.user.id;
this.applicationId = packet.d.application.id;
this.me = Transformers.ClientUser(this, packet.d.user, packet.d.application) as never;
@ -412,6 +414,9 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
}
this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
break;
default:
await this.events?.execute(packet.t as never, packet, this, shardId);
break;
}
break;
}