aboutsummaryrefslogtreecommitdiff
path: root/code/cogs/info.py
blob: f115cd3e02bd48e4dd3fa31303fccad018183d38 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import time
import discord
from discord.ext import commands
import datetime
from discord import app_commands

from global_variables import BOT_COLOR


class Info(commands.Cog):
    def __init__(self, bot):
        self.bot = bot


    @app_commands.command()
    @app_commands.describe(member="Member whose information you want to view")
    async def userinfo(
        self,
        interaction: discord.Interaction,
        member: discord.Member
    ):
        "Send account information for the given user"

        embed = discord.Embed(
            title=f"User Information For {member}",
            color=BOT_COLOR
        )

        roles = [role for role in member.roles]
        roles = f" ".join([f"{role.mention}, " for role in roles])

        embed.set_thumbnail(url = member.avatar.url)
        embed.add_field(name="Account name: ", value=f"`{str(member)}`")
        embed.add_field(name="Discord ID: ", value=f"`{str(member.id)}`")
        embed.add_field(name="Nickname: ", value=f"`{member.nick}`" or "`No nickname!`")
        embed.add_field(name="Account created at: ", value=f"`{member.created_at.strftime('%Y-%m-%d')}`")
        embed.add_field(name="Joined server at: ", value=f"`{member.joined_at.strftime('%Y-%m-%d')}`")

        if member.bot is True:
            embed.add_field(name="Discord bot? ", value="`🤖 = ✅`")
        else:
            embed.add_field(name="Discord bot?", value="`🤖 = ❌`")

        embed.add_field(name="Top role: ", value=f"{member.top_role.mention}")
        embed.add_field(name="Roles: ", inline=False, value=roles)
        embed.set_footer(text=datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%d %H:%M:%S')+" UTC")

        try:
            await interaction.response.send_message(embed=embed)

        except discord.errors.HTTPException:
            embed.remove_field(7)
            await interaction.response.send_message(embed=embed)


    @app_commands.command()
    async def botinfo(
        self,
        interaction: discord.Interaction
    ):
        "Get information about the bot. i.e. number of servers, creation date, etc."

        embed = discord.Embed(
            title=f"Bot Information",
            color=BOT_COLOR
        )
        #embed.set_thumbnail(url=self.bot.user.avatar.url)
        embed.add_field(name="Servers: ", value = f"`{len(self.bot.guilds):,}`"),
        embed.add_field(name="Account name: ", value=f"`{str(self.bot.user.name)}`")
        embed.add_field(name="Discord ID: ", value=f"`{str(self.bot.user.id)}`")
        embed.add_field(name="Bot created at: ", value=f"`{self.bot.user.created_at.strftime('%Y-%m-%d')}`"),
        embed.set_footer(text=datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%d %H:%M:%S')+" UTC")
        await interaction.response.send_message(embed=embed)


async def setup(bot):
    await bot.add_cog(Info(bot))