Jelajahi Sumber

Outsourced the userinfo command in a cogs file. Also updated the imports of the other cogs.

BaumSplitter41 4 bulan lalu
induk
melakukan
01d15961b0
4 mengubah file dengan 54 tambahan dan 22 penghapusan
  1. 1 2
      VPD_BOT/cogs/help_cache.py
  2. 0 2
      VPD_BOT/cogs/how_to_start.py
  3. 0 18
      VPD_BOT/cogs/say.py
  4. 53 0
      VPD_BOT/cogs/userinfo.py

+ 1 - 2
VPD_BOT/cogs/help_cache.py

@@ -2,8 +2,7 @@ import discord
 from discord.ext import commands
 from discord.commands import Option
 from discord.commands import slash_command
-import os
-from dotenv import load_dotenv
+
 
 class helpcache(commands.Cog):
     def __init__(self, bot: discord.Bot):

+ 0 - 2
VPD_BOT/cogs/how_to_start.py

@@ -2,8 +2,6 @@ import discord
 from discord.ext import commands
 from discord.commands import Option
 from discord.commands import slash_command
-import os
-from dotenv import load_dotenv
 
 class howtostart(commands.Cog):
     def __init__(self, bot: discord.Bot):

+ 0 - 18
VPD_BOT/cogs/say.py

@@ -9,24 +9,6 @@ class Say(commands.Cog):
     def __init__(self, bot: discord.Bot):
         self.bot = bot
 
-    intents = discord.Intents.default()
-    intents.message_content = True
-    intents.members = True
-    intents.guilds = True
-    intents.reactions = True
-
-    client = discord.Client(intents=intents)
-    debug_guilds_up = []
-    server_token = os.getenv("SERVER").split(",")
-    for i in range(len(server_token)):
-        debug_guilds_up.append(int(server_token[i]))
-    
-    bot = commands.Bot(
-    command_prefix=commands.when_mentioned_or("!"),
-    description="VicePD Bot",
-    intents=intents,
-    debug_guilds=debug_guilds_up if debug_guilds_up else None
-    )
 
 
 #Command initialization

+ 53 - 0
VPD_BOT/cogs/userinfo.py

@@ -0,0 +1,53 @@
+import discord
+from discord.ext import commands
+from discord.commands import Option
+from discord.commands import slash_command
+
+
+class userinfo(commands.Cog):
+    def __init__(self, bot: discord.Bot):
+        self.bot = bot
+
+
+#Command initialization
+    @slash_command(name="userinfo", description="Show informations of a user from this server")
+    async def userinfo(
+            self,
+            ctx,
+            user: str = Option(discord.User, "Select User"),
+        ):
+        if user is None:
+            user = ctx.author
+        elif user not in ctx.guild.members:
+            await ctx.respond("The selected user is not a member on this Server!", ephemeral=True)
+            return
+        elif user == self.bot.user:
+            await ctx.respond(f"This is me - the {self.bot.user}", ephemeral=True)
+            return
+
+        embed = discord.Embed(
+            title=f"Information about *{user.name}*",
+            description=f"Here you see all details about {user.mention}",
+            color=discord.Color.blue()
+        )
+
+        time = discord.utils.format_dt(user.created_at, "R")
+
+        embed.add_field(name="Account creation date", value=time, inline=False)
+        if len(user.roles) >= 2:
+            embed.add_field(name="Roles", value=", ".join([role.mention for role in user.roles if role.name != "@everyone"]), inline=False)
+        else:
+            embed.add_field(name="Roles", value="User has no roles", inline=False)
+        embed.add_field(name="Server join date", value=discord.utils.format_dt(user.joined_at, "R"), inline=False)
+        embed.add_field(name="User ID", value=user.id)
+
+        embed.set_thumbnail(url=user.display_avatar.url)
+        embed.set_author(name="VicePD", icon_url="https://i.imgur.com/6QteFrg.png")
+        embed.set_footer(text="VicePD - Bot | Made by BaumSplitter41")
+
+        await ctx.respond(embed=embed)
+
+
+
+def setup(bot: discord.Bot):
+    bot.add_cog(userinfo(bot))