Skip to content

Commit

Permalink
Fix an issue occurring when events are received while starting up
Browse files Browse the repository at this point in the history
  • Loading branch information
SunburntRock89 committed Jun 9, 2023
1 parent 54b1b52 commit 45b7454
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/events/allShardsReady.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import DTelClient from "../internals/client";
export default async(client: DTelClient): Promise<void> => {
winston.info("Received the all clear! Starting calls...");

client.allShardsSpawned = true;

// const allCalls = await client.db.activeCalls.findMany({
// include: {
// to: {
Expand Down
4 changes: 4 additions & 0 deletions src/internals/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class DTelClient extends Client<true> {

permsCache: Collection<string, PermissionLevel> = new Collection();

allShardsSpawned = false;

constructor(options: ClientOptions) {
super(options);
this.shardWithSupportGuild = ShardClientUtil.shardIdForGuildId(config.supportGuild.id, config.shardCount);
Expand Down Expand Up @@ -261,6 +263,8 @@ class DTelClient extends Client<true> {
}

async getGuildCount(): Promise<number> {
if (!this.allShardsSpawned) return -1;

return (await this.shard!.fetchClientValues("guilds.cache.size")).reduce((a, b) => (a as number) + (b as number), 0) as number;
}
}
Expand Down

0 comments on commit 45b7454

Please sign in to comment.