From 28d1f6d0a2a709744f5d53a113240a6dd65ad7e3 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Thu, 8 May 2025 17:37:05 +0200 Subject: [PATCH] Add total members to botinfo command --- commands/info/botinfo.js | 22 +++++++++++++++++----- tests/getGuildCount.test.js | 4 ++-- util/getGuildCount.js | 8 -------- util/getGuildInfo.js | 9 +++++++++ util/setPresence.js | 4 ++-- 5 files changed, 30 insertions(+), 17 deletions(-) delete mode 100644 util/getGuildCount.js create mode 100644 util/getGuildInfo.js diff --git a/commands/info/botinfo.js b/commands/info/botinfo.js index df700bf..a746075 100644 --- a/commands/info/botinfo.js +++ b/commands/info/botinfo.js @@ -1,6 +1,6 @@ const {EmbedBuilder} = require('discord.js'); const getCreationDate = require('../../util/getCreationDate'); -const getGuildCount = require('../../util/getGuildCount'); +const getGuildInfo = require('../../util/getGuildInfo'); @@ -8,15 +8,27 @@ module.exports = { name: 'botinfo', description: 'Shows information about the bot', execute({message, client, prefix}) { - let guildCount = getGuildCount(client) + let guildInfo = getGuildInfo(client) + let descriptionArr = [`Name: ${client.user.username}`, + `Prefix: ${prefix}`, + `Total Servers: ${guildInfo.guildCount}`, + `Total Members: ${guildInfo.totalMembers}`, + `Total Commands: ${client.commands.size}`, + `Creation Date: ${getCreationDate(client)}`, + `Source [Click Here](https://github.com/SileNce5k/discord_bot)` + ] + + let description = ""; + descriptionArr.forEach(desc => { + description += `${desc}\n`; + }) + const embed = new EmbedBuilder() .setColor(15780145) .setTitle("Information about bot") .setTimestamp() .setAuthor({name: client.user.username, iconURL: client.user.avatarURL({ format: 'png', dynamic: true, size: 2048 })}) - .addFields({ - name: "General info", value: `Name: ${client.user.username}\nPrefix: ${prefix}\nTotal Servers: ${guildCount}\nTotal Commands: ${client.commands.size}\nCreation Date: ${getCreationDate(client)}\nSource: [Click Here](https://github.com/SileNce5k/discord_bot)`, - },) + .setDescription(description) message.channel.send({embeds :[embed]}) diff --git a/tests/getGuildCount.test.js b/tests/getGuildCount.test.js index fac0cd1..cc86368 100644 --- a/tests/getGuildCount.test.js +++ b/tests/getGuildCount.test.js @@ -1,4 +1,4 @@ -const getGuildCount = require('../util/getGuildCount'); +const getGuildInfo = require('../util/getGuildInfo'); @@ -11,7 +11,7 @@ test("Testing getGuildCount", () => { client.guilds.cache.set(`num: ${j}`, j); } - expect(getGuildCount(client)).toBe(i); + expect(getGuildInfo(client).guildCount).toBe(i); } }) \ No newline at end of file diff --git a/util/getGuildCount.js b/util/getGuildCount.js deleted file mode 100644 index 5fff1e5..0000000 --- a/util/getGuildCount.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = function(client){ - let guildCount = 0; - client.guilds.cache.each(() => { - guildCount++ - }); - - return guildCount; -} \ No newline at end of file diff --git a/util/getGuildInfo.js b/util/getGuildInfo.js new file mode 100644 index 0000000..87540c6 --- /dev/null +++ b/util/getGuildInfo.js @@ -0,0 +1,9 @@ +module.exports = function(client){ + let guildCount = 0; + let totalMembers = 0; + client.guilds.cache.each(guild => { + guildCount++ + totalMembers += guild.memberCount; + }); + return {guildCount: guildCount, totalMembers: totalMembers}; +} \ No newline at end of file diff --git a/util/setPresence.js b/util/setPresence.js index b670055..2aa362b 100644 --- a/util/setPresence.js +++ b/util/setPresence.js @@ -1,9 +1,9 @@ -const getGuildCount = require("./getGuildCount") +const getGuildInfo = require("./getGuildInfo") const parseMS = require('./parseMS'); const convertDateToISOString = require('./convertDateToISOString') module.exports = function ({presenceText, presenceType, client}) { const {globalPrefix} = require ('../data/config.json') - let guildCount = getGuildCount(client) + let guildCount = getGuildInfo(client).guildCount let uptime = parseMS(client.uptime); let uptimeFormat = ""; let uptimeSingularOrPlural;