From 5bcfafd0ed4ffcd325fa88051c96f12149946df8 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 29 May 2022 21:48:12 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=88=20add=20total=20users=20to=20defau?= =?UTF-8?q?lt=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/ready/index.ts | 8 +------- src/handlers/deployCommands.ts | 2 +- src/helpers/updatePresence/index.ts | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/events/ready/index.ts b/src/events/ready/index.ts index 61ce106..bd1e060 100644 --- a/src/events/ready/index.ts +++ b/src/events/ready/index.ts @@ -13,15 +13,9 @@ export const options: IEventOptions = { }; export const execute = async (client: Client) => { - logger.info("Ready!"); + logger.info("Discord's API client is ready!"); await updatePresence(client); await devMode(client); await deployCommands(client); - - client.guilds?.cache.forEach((guild) => { - logger.silly( - `${client.user?.tag} (${client.user?.id}) is in guild: ${guild.name} (${guild.id}) with member count of ${guild.memberCount}` - ); - }); }; diff --git a/src/handlers/deployCommands.ts b/src/handlers/deployCommands.ts index 97c1786..2123da7 100644 --- a/src/handlers/deployCommands.ts +++ b/src/handlers/deployCommands.ts @@ -2,7 +2,7 @@ import { token, clientId } from "../config/discord"; import { devMode, guildId } from "../config/other"; import logger from "../logger"; -import { ApplicationCommandDataResolvable, Client } from "discord.js"; +import { Client } from "discord.js"; import { REST } from "@discordjs/rest"; import { Routes } from "discord-api-types/v9"; import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10"; diff --git a/src/helpers/updatePresence/index.ts b/src/helpers/updatePresence/index.ts index 3add873..a8c4a35 100644 --- a/src/helpers/updatePresence/index.ts +++ b/src/helpers/updatePresence/index.ts @@ -4,11 +4,20 @@ import logger from "../../logger"; // Function export default async (client: Client) => { - const status = `${client?.guilds?.cache?.size} guilds.`; + if (!client?.user) throw new Error("Client's user is undefined."); - client?.user?.setPresence({ - activities: [{ type: "WATCHING", name: status }], + const { guilds } = client; + + const memberCount = guilds.cache.reduce((a, g) => a + g.memberCount, 0); + + const guildCount = guilds.cache.size; + + const status = `${memberCount} users in ${guildCount} guilds.`; + + client.user.setPresence({ + activities: [{ type: "LISTENING", name: status }], status: "online", }); - logger?.debug(`Updated client presence to: ${status}`); + + logger.info(`Client's presence is set to "${status}"`); };