aboutsummaryrefslogtreecommitdiff
path: root/code/cogs/user_count.py
diff options
context:
space:
mode:
authorParker <contact@pkrm.dev>2024-03-31 00:10:45 -0500
committerParker <contact@pkrm.dev>2024-03-31 00:10:45 -0500
commit39026bb4e0535d31f9436e6506a38e4be0b33f30 (patch)
tree0541f46a0a27763f657d0902d523b16a0905ee79 /code/cogs/user_count.py
parent7e7f2d959cc1100604774fff78d4d67087629073 (diff)
base commit
Diffstat (limited to 'code/cogs/user_count.py')
-rw-r--r--code/cogs/user_count.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/code/cogs/user_count.py b/code/cogs/user_count.py
new file mode 100644
index 0000000..c2d7321
--- /dev/null
+++ b/code/cogs/user_count.py
@@ -0,0 +1,45 @@
+from discord.ext import commands
+import discord
+
+from global_variables import BOT_COLOR
+
+
+class UserCount(commands.Cog):
+ def __init__(self, bot):
+ self.bot = bot
+
+ @commands.command()
+ @commands.dm_only()
+ @commands.is_owner()
+ async def info(self, ctx: commands.Context):
+ total_guilds = {}
+
+ for guild in self.bot.guilds:
+ total_guilds[guild.name] = guild.member_count
+
+ # Sort the dictionary by value descending
+ total_guilds = dict(
+ sorted(total_guilds.items(), key=lambda item: item[1], reverse=True)
+ )
+
+ total_members = 0
+
+ for guild in total_guilds:
+ total_members += total_guilds[guild]
+
+ embed = discord.Embed(
+ title="User Count",
+ description=f"Total Members: `{total_members:,}`\nTotal Guilds: `{len(self.bot.guilds):,}`",
+ color=BOT_COLOR,
+ )
+ # Add the top 5 guilds to the embed
+ for guild in list(total_guilds)[:5]:
+ embed.add_field(
+ name=guild, value=f"```{total_guilds[guild]:,}```", inline=False
+ )
+
+ await ctx.send(embed=embed)
+
+
+async def setup(bot):
+ await bot.add_cog(UserCount(bot))