aboutsummaryrefslogtreecommitdiff
path: root/code/cogs/owner/info.py
blob: 7cd1d089b5309f23d4d079e5299f33e9790a5c5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from discord.ext import commands
import discord

from global_variables import BOT_COLOR


class Info(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):,}`\n\nTotal Players: `{self.bot.lavalink.nodes[0].stats.playing_players}`\nLoad: `{round(self.bot.lavalink.nodes[0].stats.lavalink_load * 100, 2)}`",
            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(Info(bot))