diff --git a/cogs/moderation_cog.py b/cogs/moderation_cog.py index bbac2dd..c8145ad 100644 --- a/cogs/moderation_cog.py +++ b/cogs/moderation_cog.py @@ -1,43 +1,57 @@ import datetime -from discord import app_commands, ui +from discord import app_commands from discord.ext import commands import discord -from utils import * -from constants import * -from api import app import aiohttp + class moderation(commands.Cog): def __init__(self, bot): self.bot = bot - async def unban_autocomplete(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]: + async def unban_autocomplete( + self, interaction: discord.Interaction, current: str + ) -> list[app_commands.Choice[str]]: banned_users = await interaction.guild.bans() print(banned_users) - return [app_commands.Choice(name=f"{ban_entry.user.name}", value=str(ban_entry.user.id)) for ban_entry in banned_users] + return [ + app_commands.Choice( + name=f"{ban_entry.user.name}", value=str(ban_entry.user.id) + ) + for ban_entry in banned_users + ] @app_commands.command(name="ban", description="Bans a user from the server") @app_commands.guild_only() @app_commands.default_permissions(administrator=True) - @app_commands.describe(user = "The user to ban", reason="The reason for banning the user") - async def ban(self, interaction: discord.Interaction, user: discord.Member, *, reason:str|None = None): - + @app_commands.describe( + user="The user to ban", reason="The reason for banning the user" + ) + async def ban( + self, + interaction: discord.Interaction, + user: discord.Member, + *, + reason: str | None = None, + ): await interaction.guild.ban(user, reason=reason) embed = discord.Embed( title="User Banned", description=f"{user.mention} was banned from the server", color=discord.Color.brand_red(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) embed.add_field(name=f"User Id `{user.id}`", value="** **", inline=False) - embed.add_field(name=f"Banned By {interaction.user.mention}", value="** **", inline=False) + embed.add_field( + name=f"Banned By {interaction.user.mention}", value="** **", inline=False + ) embed.add_field(name="Reason", value=reason, inline=False) try: embed.set_thumbnail(url=user.avatar.url) - except: + except Exception: embed.set_thumbnail(url=user.default_avatar.url) embed.set_footer(text=f"{user.name} Banned") @@ -56,57 +70,83 @@ async def unban(self, interaction, user: str): title="User Unbanned", description=f"{user.mention} was unbanned from the server", color=discord.Color.green(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) embed.add_field(name=f"User Id `{user.id}`", value="** **", inline=False) - embed.add_field(name=f"Unbanned By {interaction.user.mention}", value="** **", inline=False) + embed.add_field( + name=f"Unbanned By {interaction.user.mention}", value="** **", inline=False + ) try: embed.set_thumbnail(url=user.avatar.url) - except: + except Exception: embed.set_thumbnail(url=user.default_avatar.url) embed.set_footer(text=f"{user.name} Unbanned") await interaction.response.send_message(embed=embed) - @app_commands.command(name="kick", description="Kicks a user from the server") @app_commands.guild_only() @app_commands.default_permissions(administrator=True) - @app_commands.describe(user = "The user to kick", reason="The reason for kicking the user") - async def kick(self, interaction: discord.Interaction, user: discord.Member, *, reason:str|None = None): + @app_commands.describe( + user="The user to kick", reason="The reason for kicking the user" + ) + async def kick( + self, + interaction: discord.Interaction, + user: discord.Member, + *, + reason: str | None = None, + ): await interaction.guild.kick(user, reason=reason) embed = discord.Embed( title="User Kicked", description=f"{user.mention} was kicked from the server", color=discord.Color.orange(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) embed.add_field(name=f"User Id `{user.id}`", value="** **", inline=False) - embed.add_field(name=f"Kicked By {interaction.user.mention}", value="** **", inline=False) + embed.add_field( + name=f"Kicked By {interaction.user.mention}", value="** **", inline=False + ) embed.add_field(name="Reason", value=reason, inline=False) try: embed.set_thumbnail(url=user.avatar.url) - except: + except Exception: embed.set_thumbnail(url=user.default_avatar.url) embed.set_footer(text=f"{user.name} Kicked") await interaction.response.send_message(embed=embed) - @app_commands.command(name="purge", description="Purges a certain amount of messages") + @app_commands.command( + name="purge", description="Purges a certain amount of messages" + ) @app_commands.guild_only() @app_commands.default_permissions(administrator=True) - @app_commands.describe(amount = "The amount of messages to purge", channel="The channel to purge the messages from") - async def purge(self, interaction:discord.Interaction, amount: int, channel: discord.TextChannel = None): - + @app_commands.describe( + amount="The amount of messages to purge", + channel="The channel to purge the messages from", + ) + async def purge( + self, + interaction: discord.Interaction, + amount: int, + channel: discord.TextChannel = None, + ): if not interaction.user.guild_permissions.manage_messages: - await interaction.response.send_message(embed=discord.Embed(description="You don't have the permissions to do that!", color=discord.Color.red()), ephemeral=True) + await interaction.response.send_message( + embed=discord.Embed( + description="You don't have the permissions to do that!", + color=discord.Color.red(), + ), + ephemeral=True, + ) return if channel is None: @@ -121,7 +161,7 @@ def check(msg): title="Purge", description=f"Purged {amount} messages", color=discord.Color.green(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) embed.add_field(name="Channel", value=channel.mention, inline=False) embed.set_footer(text=f"Purged {amount} messages") @@ -131,14 +171,31 @@ def check(msg): @app_commands.command(name="slowmode", description="Sets a slowmode for a channel") @app_commands.guild_only() @app_commands.default_permissions(administrator=True) - @app_commands.describe(time= "The time in seconds for the slowmode", channel="The channel to set the slowmode in") - async def slowmode(self, interaction, time: int, channel: discord.TextChannel = None): + @app_commands.describe( + time="The time in seconds for the slowmode", + channel="The channel to set the slowmode in", + ) + async def slowmode( + self, interaction, time: int, channel: discord.TextChannel = None + ): if time > 21600: - await interaction.response.send_message(embed=discord.Embed(description="Slow Mode cannot be more than 6 hours.", color=discord.Color.red()), ephemeral=True) + await interaction.response.send_message( + embed=discord.Embed( + description="Slow Mode cannot be more than 6 hours.", + color=discord.Color.red(), + ), + ephemeral=True, + ) return if time < 0: - await interaction.response.send_message(embed=discord.Embed(description="Slow Mode cannot be less than 0 seconds.", color=discord.Color.red()), ephemeral=True) + await interaction.response.send_message( + embed=discord.Embed( + description="Slow Mode cannot be less than 0 seconds.", + color=discord.Color.red(), + ), + ephemeral=True, + ) return await interaction.response.defer() @@ -150,38 +207,40 @@ async def slowmode(self, interaction, time: int, channel: discord.TextChannel = title="Slowmode Set", description=f"Set the slowmode to `{time} seconds`", color=discord.Color.green(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) - embed.set_footer(text=f"Slowmode set") + embed.set_footer(text="Slowmode set") embed.add_field(name="Channel", value=channel.mention, inline=False) await interaction.followup.send(embed=embed) - @app_commands.command(name="add-role", description="Adds a role to a user") @app_commands.guild_only() @app_commands.default_permissions(administrator=True) - @app_commands.describe(user="The user to add the role to", role="The role to add to the user") + @app_commands.describe( + user="The user to add the role to", role="The role to add to the user" + ) async def add_role(self, interaction, user: discord.Member, role: discord.Role): await user.add_roles(role) embed = discord.Embed( title="Role Added", description=f"Added the role {role.mention} to {user.mention}", color=discord.Color.green(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) try: embed.set_thumbnail(url=user.avatar.url) - except: + except Exception: embed.set_thumbnail(url=user.default_avatar.url) - embed.set_footer(text=f"Role added") + embed.set_footer(text="Role added") await interaction.response.send_message(embed=embed) - @app_commands.command(name="remove-role", description="Removes a role from a user") @app_commands.guild_only() @app_commands.default_permissions(administrator=True) - @app_commands.describe(user="The user to remove the role from", role="The role to remove from the user") + @app_commands.describe( + user="The user to remove the role from", role="The role to remove from the user" + ) async def removerole(self, interaction, user: discord.Member, role: discord.Role): if role in user.roles: await user.remove_roles(role) @@ -189,13 +248,13 @@ async def removerole(self, interaction, user: discord.Member, role: discord.Role title="Role Removed", description=f"Removed the role {role.mention} from {user.mention}", color=discord.Color.red(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) try: embed.set_thumbnail(url=user.avatar.url) - except: + except Exception: embed.set_thumbnail(url=user.default_avatar.url) - embed.set_footer(text=f"Role removed") + embed.set_footer(text="Role removed") await interaction.response.send_message(embed=embed) else: @@ -210,27 +269,50 @@ async def removerole(self, interaction, user: discord.Member, role: discord.Role @app_commands.command(name="create-channel", description="Creates a channel") @app_commands.guild_only() @app_commands.default_permissions(administrator=True) - @app_commands.describe(name="The name of the channel", category="The category to create the channel in", private="Whether the channel should be private or not", emoji="The emoji to use for the channel") - async def createchannel(self, interaction, emoji: str, name: str, category: discord.CategoryChannel = None, private: bool = False): + @app_commands.describe( + name="The name of the channel", + category="The category to create the channel in", + private="Whether the channel should be private or not", + emoji="The emoji to use for the channel", + ) + async def createchannel( + self, + interaction, + emoji: str, + name: str, + category: discord.CategoryChannel = None, + private: bool = False, + ): name = f"{emoji}|{name}" if emoji else name if not private: await interaction.guild.create_text_channel(name=name, category=category) else: - await interaction.guild.create_text_channel(name=name, category=category, overwrites={interaction.guild.default_role: discord.PermissionOverwrite(read_messages=False)}) + await interaction.guild.create_text_channel( + name=name, + category=category, + overwrites={ + interaction.guild.default_role: discord.PermissionOverwrite( + read_messages=False + ) + }, + ) embed = discord.Embed( title="Channel Created", description=f"Created the channel `{name}`", color=discord.Color.green(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) - embed.set_footer(text=f"Channel created") + embed.set_footer(text="Channel created") if category: embed.add_field(name="Category", value=category.mention, inline=False) - await interaction.response.send_message(embed=embed) if not private else await interaction.response.send_message(embed=embed, ephemeral=True) - + await interaction.response.send_message( + embed=embed + ) if not private else await interaction.response.send_message( + embed=embed, ephemeral=True + ) @app_commands.command(name="delete-channel", description="Deletes a channel") @app_commands.guild_only() @@ -242,29 +324,34 @@ async def deletechannel(self, interaction, channel: discord.TextChannel): title="Channel Deleted", description=f"Deleted the channel `{channel.name}`", color=discord.Color.red(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) - embed.set_footer(text=f"Channel deleted") + embed.set_footer(text="Channel deleted") await interaction.response.send_message(embed=embed) - @app_commands.command(name="create-role", description="Creates a role") @app_commands.guild_only() @app_commands.default_permissions(administrator=True) - @app_commands.describe(name="The name of the role", mentionable="Whether the role should be mentionable") - async def createrole(self, interaction, name: str, hoist: bool = False, mentionable: bool = False): - role = await interaction.guild.create_role(name=name, hoist=hoist, mentionable=mentionable) + @app_commands.describe( + name="The name of the role", + mentionable="Whether the role should be mentionable", + ) + async def createrole( + self, interaction, name: str, hoist: bool = False, mentionable: bool = False + ): + role = await interaction.guild.create_role( + name=name, hoist=hoist, mentionable=mentionable + ) embed = discord.Embed( title="Role Created", description=f"Created the role {role.mention}", - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) - embed.set_footer(text=f"Role created") + embed.set_footer(text="Role created") await interaction.response.send_message(embed=embed) - @app_commands.command(name="delete-role", description="Deletes a role") @app_commands.guild_only() @app_commands.default_permissions(administrator=True) @@ -275,31 +362,31 @@ async def deleterole(self, interaction, role: discord.Role): title="Role Deleted", description=f"Deleted the role {role.mention}", color=discord.Color.red(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) - embed.set_footer(text=f"Role deleted") + embed.set_footer(text="Role deleted") await interaction.response.send_message(embed=embed) - @app_commands.command(name="create-category", description="Creates a category") @app_commands.guild_only() @app_commands.default_permissions(administrator=True) - @app_commands.describe(name="The name of the category", emoji="The emoji to use for the category") - async def createcategory(self, interaction, emoji:str, name: str): + @app_commands.describe( + name="The name of the category", emoji="The emoji to use for the category" + ) + async def createcategory(self, interaction, emoji: str, name: str): name = f"{emoji}|{name}" if emoji else name category = await interaction.guild.create_category(name=name) embed = discord.Embed( title="Category Created", description=f"Created the category {category.name}", color=discord.Color.green(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) - embed.set_footer(text=f"Category created") + embed.set_footer(text="Category created") await interaction.response.send_message(embed=embed) - @app_commands.command(name="delete-category", description="Deletes a category") @app_commands.guild_only() @app_commands.default_permissions(administrator=True) @@ -310,13 +397,12 @@ async def deletecategory(self, interaction, category: discord.CategoryChannel): title="Category Deleted", description=f"Deleted the category {category.name}", color=discord.Color.red(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) - embed.set_footer(text=f"Category deleted") + embed.set_footer(text="Category deleted") await interaction.response.send_message(embed=embed) - async def get_image(self, url: str) -> discord.Asset: async with aiohttp.ClientSession() as session: async with session.get(url) as response: @@ -334,64 +420,97 @@ async def createemoji(self, interaction, name: str, url: str): title="Emoji Created", description=f"Created the emoji <:{name}:{emoji.id}>", color=discord.Color.green(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) embed.add_field(name="Name", value=name, inline=False) embed.add_field(name="Url", value=url, inline=False) embed.set_thumbnail(url=url) - embed.set_footer(text=f"Emoji created") + embed.set_footer(text="Emoji created") await interaction.response.send_message(embed=embed) @app_commands.command(name="edit-channel", description="Edits a channel") @app_commands.guild_only() @app_commands.default_permissions(administrator=True) - @app_commands.describe(channel="The channel to edit", name="The new name of the channel", category="The new category of the channel", private="Whether the channel should be private or not", slowmode="The new slowmode of the channel") - async def editchannel(self, interaction, channel: discord.TextChannel, emoji: str, name: str, category: discord.CategoryChannel = None, private: bool = False, slowmode: int = None): - name = f"{emoji}|{name}" if not emoji.strip()=="" else name + @app_commands.describe( + channel="The channel to edit", + name="The new name of the channel", + category="The new category of the channel", + private="Whether the channel should be private or not", + slowmode="The new slowmode of the channel", + ) + async def editchannel( + self, + interaction, + channel: discord.TextChannel, + emoji: str, + name: str, + category: discord.CategoryChannel = None, + private: bool = False, + slowmode: int = None, + ): + name = f"{emoji}|{name}" if not emoji.strip() == "" else name if not category: category = channel.category - await channel.edit(name=name, category=category, overwrites={interaction.guild.default_role: discord.PermissionOverwrite(read_messages=False)} if private else None, slowmode_delay=slowmode) + await channel.edit( + name=name, + category=category, + overwrites={ + interaction.guild.default_role: discord.PermissionOverwrite( + read_messages=False + ) + } + if private + else None, + slowmode_delay=slowmode, + ) embed = discord.Embed( title="Channel Edited", description=f"Edited the channel {channel.name}", color=discord.Color.green(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + timestamp=datetime.datetime.now(datetime.timezone.utc), ) - embed.set_footer(text=f"Channel edited") + embed.set_footer(text="Channel edited") await interaction.response.send_message(embed=embed) - - @app_commands.command(name="kick", description="Kicks a user from the server") + @app_commands.command(name="archive-channel", description="Archives a channel") @app_commands.guild_only() @app_commands.default_permissions(administrator=True) - @app_commands.describe(user="The user to kick", reason="The reason for kicking the user") - async def kick(self, interaction: discord.Interaction, user: discord.Member, *, reason:str|None = None): - await interaction.guild.kick(user, reason=reason) - - embed = discord.Embed( - title="User Kicked", - description=f"{user.mention} was kicked from the server", - color=discord.Color.orange(), - timestamp=datetime.datetime.now(datetime.timezone.utc) + @app_commands.describe(channel="Moves the selected channel to the archive category") + async def archivechannel( + self, interaction, channel: discord.TextChannel, lock: bool = False + ): + archive_category = next( + ( + category + for category in interaction.guild.categories + if "archive" in category.name.lower() + ), + None, ) + if not archive_category: + archive_category = await interaction.guild.create_category("Archived") - embed.add_field(name=f"User Id `{user.id}`", value="** **", inline=False) - embed.add_field(name=f"Kicked By {interaction.user.mention}", value="** **", inline=False) - embed.add_field(name="Reason", value=reason, inline=False) - - try: - embed.set_thumbnail(url=user.avatar.url) - except: - embed.set_thumbnail(url=user.default_avatar.url) + await channel.edit(category=archive_category) + if lock: + await channel.set_permissions( + interaction.guild.default_role, send_messages=False + ) - embed.set_footer(text=f"{user.name} Kicked") + embed = discord.Embed( + title="Channel Archived", + description=f"Archived the channel `{channel.name}`", + color=discord.Color.green(), + timestamp=datetime.datetime.now(datetime.timezone.utc), + ) + embed.set_footer(text="Channel archived") await interaction.response.send_message(embed=embed) + async def setup(bot): await bot.add_cog(moderation(bot)) - print("Loaded moderation_cog.py") \ No newline at end of file + print("Loaded moderation_cog.py") diff --git a/cogs/server_info.py b/cogs/server_info.py index 669ff59..d18bece 100644 --- a/cogs/server_info.py +++ b/cogs/server_info.py @@ -1,53 +1,88 @@ -import datetime -from discord import app_commands, ui +from discord import app_commands from discord.ext import commands import discord -from utils import * -from constants import * -from api import app -import aiohttp + class server_info(commands.Cog): def __init__(self, bot): self.bot = bot - @app_commands.command(name="member-count", description="Get the number of members in the server") + @app_commands.command( + name="member-count", description="Get the number of members in the server" + ) @app_commands.guild_only() - async def member_count(self, interaction:discord.Interaction): - human_members = len([member for member in interaction.guild.members if not member.bot]) + async def member_count(self, interaction: discord.Interaction): + human_members = len( + [member for member in interaction.guild.members if not member.bot] + ) embed = discord.Embed( title="Member Count", description=f"Total Members: {len(interaction.guild.members)}", - color=discord.Color.green() + color=discord.Color.green(), ) embed.add_field(name="Humans", value=f"```{human_members}```", inline=True) - embed.add_field(name="Bots", value=f"```{len(interaction.guild.members) - human_members}```", inline=True) + embed.add_field( + name="Bots", + value=f"```{len(interaction.guild.members) - human_members}```", + inline=True, + ) - embed.set_footer(text=f"Requested by {interaction.user.display_name}", icon_url=interaction.user.avatar.url) + embed.set_footer( + text=f"Requested by {interaction.user.display_name}", + icon_url=interaction.user.avatar.url, + ) await interaction.response.send_message(embed=embed) - @app_commands.command(name="links", description="Get Links to various Ivirius Products") + @app_commands.command( + name="links", description="Get Links to various Ivirius Products" + ) @app_commands.guild_only() - async def links(self, interaction:discord.Interaction): + async def links(self, interaction: discord.Interaction): embed = discord.Embed( title="Ivirius Links", description="Here are some links to Ivirius products", - color=discord.Color.green() + color=discord.Color.green(), ) - embed.add_field(name="Website <:Ivirius:1290061289258745896>", value="https://ivirius.com/", inline=False) - embed.add_field(name="Rebound 11 <:Rebound11:1290061222494081075>", value="https://ivirius.com/rebound11", inline=False) - embed.add_field(name="Ivirius Text Editor Plus <:TextEditorPlus:1290061177140936704>", value="https://ivirius.com/ivirius-text-editor-plus", inline=False) - embed.add_field(name="Ivirius Text Editor <:TextEditor:1290061049352949791>", value="https://ivirius.com/ivirius-text-editor/", inline=False) - embed.add_field(name="Crimson UI <:CrimsonUI:1290061257361064062>", value="https://ivirius.com/crimsonui", inline=False) + embed.add_field( + name="Website <:Ivirius:1290061289258745896>", + value="https://ivirius.com/", + inline=False, + ) + embed.add_field( + name="Rebound 11 <:Rebound11:1290061222494081075>", + value="https://ivirius.com/rebound11", + inline=False, + ) + embed.add_field( + name="Ivirius Text Editor Plus <:TextEditorPlus:1290061177140936704>", + value="https://ivirius.com/ivirius-text-editor-plus", + inline=False, + ) + embed.add_field( + name="Ivirius Text Editor <:TextEditor:1290061049352949791>", + value="https://ivirius.com/ivirius-text-editor/", + inline=False, + ) + embed.add_field( + name="Crimson UI <:CrimsonUI:1290061257361064062>", + value="https://ivirius.com/crimsonui", + inline=False, + ) - embed.set_footer(text=f"Requested by {interaction.user.display_name}", icon_url=interaction.user.avatar.url if interaction.user.avatar else interaction.user.default_avatar.url) + embed.set_footer( + text=f"Requested by {interaction.user.display_name}", + icon_url=interaction.user.avatar.url + if interaction.user.avatar + else interaction.user.default_avatar.url, + ) await interaction.response.send_message(embed=embed) + async def setup(bot): await bot.add_cog(server_info(bot)) - print("Loaded server_info.py") \ No newline at end of file + print("Loaded server_info.py") diff --git a/main.py b/main.py index 243b769..0fe1c2d 100644 --- a/main.py +++ b/main.py @@ -2,20 +2,19 @@ import os import datetime import discord -from discord.ext import commands, tasks -from api import * +from discord.ext import commands +from api import keep_alive import statistics import time import sys -from api import * -from utils import * -from constants import * +from constants import TOKEN load_dotenv() start_time = None latencies = [] + class zippyBot(commands.Bot): def __init__(self): super().__init__( @@ -23,7 +22,6 @@ def __init__(self): ) self.synced = False - async def on_ready(self): await load() @@ -35,7 +33,8 @@ async def on_ready(self): activity=discord.CustomActivity( name="Custom Status", state="Watching Ivirius Text Editor Plus", - ), status=discord.Status.do_not_disturb + ), + status=discord.Status.do_not_disturb, ) if not self.synced: await self.tree.sync() @@ -53,6 +52,7 @@ async def load(): if filename.endswith(".py"): await bot.load_extension(f"cogs.{filename[:-3]}") + @bot.event async def on_message(message): if message.author == bot.user: @@ -63,44 +63,46 @@ async def on_message(message): @bot.event async def on_member_join(member): + if member.guild.id != 1137161703000375336: + return + embed = discord.Embed( title="Welcome to the server!", description=f"Welcome to the server {member.name}! Please read the rules and have fun!", color=discord.Color.brand_red(), ) - await member.send( - embed=embed - ) + await member.send(embed=embed) + @bot.event async def on_member_remove(member): - print(member) - if member.guild.id == 1137161703000375336: - # Get user information - user = member.name - nickname = member.nick - join_date = member.joined_at - total_time = datetime.datetime.now() - join_date - - join_date_formatted = join_date.strftime("%Y-%m-%d %H:%M:%S") - total_time_formatted = str(total_time) - - embed = discord.Embed( - title="Goodbye!", - description=f"**{user}** ({nickname}) has left the server.", - color=discord.Color.red(), - ) + if member.guild.id != 1137161703000375336: + return - embed.add_field(name="Join Date", value=join_date_formatted, inline=False) - embed.add_field( - name="Total Time in Server", value=total_time_formatted, inline=False - ) + user = member.name + nickname = member.nick + join_date = member.joined_at + total_time = datetime.datetime.now() - join_date - roles = [role.mention for role in member.roles] - embed.add_field(name="Roles", value=", ".join(roles), inline=False) + join_date_formatted = join_date.strftime("%Y-%m-%d %H:%M:%S") + total_time_formatted = str(total_time) - channel = bot.get_channel(1188420266234228809) - await channel.send(embed=embed) + embed = discord.Embed( + title="Goodbye!", + description=f"**{user}** ({nickname}) has left the server.", + color=discord.Color.red(), + ) + + embed.add_field(name="Join Date", value=join_date_formatted, inline=False) + embed.add_field( + name="Total Time in Server", value=total_time_formatted, inline=False + ) + + roles = [role.mention for role in member.roles] + embed.add_field(name="Roles", value=", ".join(roles), inline=False) + + channel = bot.get_channel(1188420266234228809) + await channel.send(embed=embed) @bot.event @@ -219,7 +221,9 @@ async def ping(ctx): end = time.perf_counter() latency = (end - ctx.start) * 1000 - embed.add_field(name="Bot Latency", value=f"{bot.latency * 1000:.2f} ms", inline=False) + embed.add_field( + name="Bot Latency", value=f"{bot.latency * 1000:.2f} ms", inline=False + ) embed.add_field(name="Message Latency", value=f"{latency:.2f} ms", inline=False) # Calculate the average ping of the bot in the last 10 minutes