fix: Fixed bug in postBotStats resulting in guildCount being NaN

This commit is contained in:
Marius Begby committed 2023-09-03 22:28:14 +02:00
1 parent e37bbf66c9
commit 57c83ff487
1 file changed
+10 -11
+10 -11
View File
@@ -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 https from 'node:https';
import { Logger } from 'pino';
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
import { PostBotStatsParams, PostBotStatsSite } from '../../types/utilTypes'; import { PostBotStatsParams, PostBotStatsSite } from '../../types/utilTypes';
import { Logger } from 'pino';
import { ClientRequest, ClientRequestArgs } from 'node:http';
export const postBotStats = async ({ client, executionId }: PostBotStatsParams) => { export const postBotStats = async ({ client, executionId }: PostBotStatsParams) => {
const logger: Logger = loggerModule.child({ const logger: Logger = loggerModule.child({
@@ -25,18 +24,18 @@ export const postBotStats = async ({ client, executionId }: PostBotStatsParams)
const shardId: number = client.shard.ids[0]; const shardId: number = client.shard.ids[0];
logger.debug('Gathering data about guild and member count from shards...'); logger.debug('Gathering data about guild and member count from shards...');
await client.shard await client!
.fetchClientValues('guilds.cache') .shard!.fetchClientValues('guilds.cache')
.then((results) => { .then((results) => {
const guildCaches: Collection<string, Guild>[] = results as Collection<string, Guild>[]; const guildCaches: Guild[][] = results as Guild[][];
guildCaches.map((guildCache) => { guildCaches.map((guildCache: Guild[]) => {
if (guildCache) { if (guildCache) {
guildCount += guildCache.size; guildCount += guildCache.length;
memberCount += guildCache.reduce((acc, guild) => acc + guild.memberCount, 0); 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) => { .catch((error) => {
logger.error(error, 'Failed to fetch client values from shards.'); logger.error(error, 'Failed to fetch client values from shards.');