Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
fix: Fixed bug in postBotStats resulting in guildCount being NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusbegby committed Sep 3, 2023
1 parent e37bbf6 commit 57c83ff
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/utils/other/postBotStats.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Collection, Guild } from 'discord.js';
import { Guild } from 'discord.js';
import { ClientRequest, ClientRequestArgs } from 'node:http';
import https from 'node:https';

import { Logger } from 'pino';
import loggerModule from '../../services/logger';
import { PostBotStatsParams, PostBotStatsSite } from '../../types/utilTypes';
import { Logger } from 'pino';
import { ClientRequest, ClientRequestArgs } from 'node:http';

export const postBotStats = async ({ client, executionId }: PostBotStatsParams) => {
const logger: Logger = loggerModule.child({
Expand All @@ -25,18 +24,18 @@ export const postBotStats = async ({ client, executionId }: PostBotStatsParams)
const shardId: number = client.shard.ids[0];

logger.debug('Gathering data about guild and member count from shards...');
await client.shard
.fetchClientValues('guilds.cache')
await client!
.shard!.fetchClientValues('guilds.cache')
.then((results) => {
const guildCaches: Collection<string, Guild>[] = results as Collection<string, Guild>[];
guildCaches.map((guildCache) => {
const guildCaches: Guild[][] = results as Guild[][];
guildCaches.map((guildCache: Guild[]) => {
if (guildCache) {
guildCount += guildCache.size;
memberCount += guildCache.reduce((acc, guild) => acc + guild.memberCount, 0);
guildCount += guildCache.length;
memberCount += guildCache.reduce((acc: number, guild: Guild) => acc + guild.memberCount, 0);
}
});

logger.debug('Successfully fetched client values from shards');
logger.debug('Successfully fetched client values from shards.');
})
.catch((error) => {
logger.error(error, 'Failed to fetch client values from shards.');
Expand Down

0 comments on commit 57c83ff

Please # to comment.