import datetime import discord from discord import app_commands from discord.ext import commands class User(commands.Cog): def __init__(self, bot): self.bot = bot @commands.Cog.listener() async def on_ready(self): print("User Online") user = app_commands.Group(name="user", description="Manage users in the server") @user.command(name="kick", description="Kicks a user") @commands.has_permissions(kick_members=True) async def kick(self, interaction: discord.Interaction, member: discord.Member, *, reason: str = None): if member.id == interaction.user.id: await interaction.response.send_message("You cannot kick yourself.") return guild = interaction.guild embed = discord.Embed(title="Kick", description=f"{member.mention} has been kicked for {reason}", color=interaction.user.color) member_embed = discord.Embed(title="Kicked", description=f"You have been kicked in {guild.name} for {reason}", color=member.color) await interaction.response.send_messaged(embed=embed) await member.send(embed=member_embed) await member.kick(reason=reason) @user.command(name="ban", description="Bans a user") @commands.has_permissions(ban_members=True) async def ban(self, interaction: discord.Interaction, member: discord.Member, *, reason: str = None): if member.id == interaction.user.id: await interaction.response.send_message("You cannot ban yourself.") return ban_message = discord.Embed(title="Ban", description=f"{member.mention} has been banned in the server for {reason}", color=interaction.user.color) ban_member_message = discord.Embed(title="Banned", description=f"You have been banned for {reason}", color=member.color) await member.send(embed=ban_member_message) await member.ban(reason=reason) await interaction.response.send_message(embed=ban_message) @user.command(name="nick", description="Sets a users nickname") @commands.has_permissions(manage_nicknames=True) async def nick(self, interaction: discord.Interaction, nick: str, user: discord.Member = None): if user is None: user = interaction.user await user.edit(nick=nick) await interaction.response.send_message(f"Set {user.mention}'s nickname to {nick}", ephemeral=True) @user.command(name="timeout", description="Timeout a user") @commands.has_permissions(manage_messages=True) async def timeout(self, interaction: discord.Interaction, user: discord.Member, time: int, reason: str = None): if user.id is interaction.user.id: await interaction.response.send_message("You can't timeout yourself") else: await user.timeout(datetime.timedelta(minutes=time), reason=reason) await interaction.response.send_Message(f"{user.mention} has been timed out for {reason}", ephemeral=True) @user.command(name="untimeout", description="Remove a users timeout") @commands.has_permissions(manage_messages=True) async def untimeout(self, interaction: discord.Interaction, user: discord.Member): await user.timeout(None) await interaction.response.send_message(f"{user.mention} has been removed from timeout", ephemeral=True) @user.command(name="avatar", description="Shows a users avatar") async def avatar(self, interaction: discord.Interaction, user: discord.Member = None): if user == None: user = interaction.user em = discord.Embed(title=f"{user.name}'s Avatar", color=user.color) em.set_image(url=user.avatar) await interaction.response.send_message(embed=em) @user.command(name="info", description="Shows info about the user") async def info(self, interaction: discord.Interaction, user: discord.Member = None): if user is None: user = interaction.user em = discord.Embed(title=f"{user.name}'s Info", description=f"Shows info about {user.name}", color=user.color) em.add_field(name="Name", value=user.name, inline=False) em.add_field(name="ID", value=user.id, inline=False) em.add_field(name="Status", value=user.status, inline=False) em.add_field(name="Top Role", value=user.top_role.mention, inline=False) em.add_field(name="Joined At", value=user.joined_at.strftime("%a, %#d %B %Y, %I:%M %p UTC"), inline=False) em.add_field(name="Created At", value=user.created_at.strftime("%a, %#d %B %Y, %I:%M %p UTC"), inline=False) em.set_thumbnail(url=user.avatar) await interaction.response.send_message(embed=em) async def setup(bot): await bot.add_cog(User(bot))