chore: (description) improve embeds for warnings

Refactored embed creation and sending in moderation warnings and owner cog management for consistency and improved user feedback. Added author and title fields to embeds, centralized embed sending logic, and enhanced error reporting with exception details. Moved NotOwner error handling from bot.py to cog_management.py for owner commands.
This commit is contained in:
neoarz
2025-09-16 07:17:33 -04:00
parent 34b034bdcd
commit 7fde0b82ad
3 changed files with 48 additions and 16 deletions

4
bot.py
View File

@@ -271,10 +271,6 @@ class DiscordBot(commands.Bot):
) )
await context.send(embed=embed) await context.send(embed=embed)
elif isinstance(error, commands.NotOwner): elif isinstance(error, commands.NotOwner):
embed = discord.Embed(
description="You are not the owner of the bot!", color=0xE02B2B
)
await context.send(embed=embed)
if context.guild: if context.guild:
self.logger.warning( self.logger.warning(
f"{context.author} (ID: {context.author.id}) tried to execute an owner only command in the guild {context.guild.name} (ID: {context.guild.id}), but the user is not an owner of the bot." f"{context.author} (ID: {context.author.id}) tried to execute an owner only command in the guild {context.guild.name} (ID: {context.guild.id}), but the user is not an owner of the bot."

View File

@@ -38,9 +38,11 @@ class Warnings(commands.Cog, name="warnings"):
if context.invoked_subcommand is None: if context.invoked_subcommand is None:
embed = discord.Embed( embed = discord.Embed(
title="Warning",
description="Please specify a subcommand.\n\n**Subcommands:**\n`add` - Add a warning to a user.\n`remove` - Remove a warning from a user.\n`list` - List all warnings of a user.", description="Please specify a subcommand.\n\n**Subcommands:**\n`add` - Add a warning to a user.\n`remove` - Remove a warning from a user.\n`list` - List all warnings of a user.",
color=0x7289DA, color=0x7289DA,
) )
embed.set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
await self.send_embed(context, embed) await self.send_embed(context, embed)
@warning.command( @warning.command(
@@ -92,6 +94,7 @@ class Warnings(commands.Cog, name="warnings"):
await member.send(embed=dm_embed) await member.send(embed=dm_embed)
except: except:
fallback = discord.Embed( fallback = discord.Embed(
title="Warning",
description=f"{member.mention}, you were warned by **{context.author}**!\nReason: {reason}", description=f"{member.mention}, you were warned by **{context.author}**!\nReason: {reason}",
color=0xE02B2B, color=0xE02B2B,
) )
@@ -127,6 +130,7 @@ class Warnings(commands.Cog, name="warnings"):
) )
total = await self.bot.database.remove_warn(warn_id, user.id, context.guild.id) total = await self.bot.database.remove_warn(warn_id, user.id, context.guild.id)
embed = discord.Embed( embed = discord.Embed(
title="Warning",
description=f"I've removed the warning **#{warn_id}** from **{member}**!\nTotal warns for this user: {total}", description=f"I've removed the warning **#{warn_id}** from **{member}**!\nTotal warns for this user: {total}",
color=0x7289DA, color=0x7289DA,
) )

View File

@@ -8,6 +8,16 @@ class CogManagement(commands.Cog, name="cog_management"):
def __init__(self, bot) -> None: def __init__(self, bot) -> None:
self.bot = bot self.bot = bot
async def send_embed(self, context: Context, embed: discord.Embed, *, ephemeral: bool = False) -> None:
interaction = getattr(context, "interaction", None)
if interaction is not None:
if interaction.response.is_done():
await interaction.followup.send(embed=embed, ephemeral=ephemeral)
else:
await interaction.response.send_message(embed=embed, ephemeral=ephemeral)
else:
await self.send_embed(context, embed)
@commands.hybrid_command( @commands.hybrid_command(
name="load", name="load",
description="Load a cog", description="Load a cog",
@@ -23,16 +33,19 @@ class CogManagement(commands.Cog, name="cog_management"):
""" """
try: try:
await self.bot.load_extension(f"cogs.{cog}") await self.bot.load_extension(f"cogs.{cog}")
except Exception: except Exception as e:
embed = discord.Embed( embed = discord.Embed(
description=f"Could not load the `{cog}` cog.", color=0xE02B2B title="Error",
description=f"Could not load the `{cog}` cog.\n```{str(e)}```", color=0xE02B2B
) )
await context.send(embed=embed) embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed, ephemeral=True)
return return
embed = discord.Embed( embed = discord.Embed(
description=f"Successfully loaded the `{cog}` cog.", color=0xBEBEFE description=f"Successfully loaded the `{cog}` cog.", color=0xBEBEFE
) )
await context.send(embed=embed) embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed)
@commands.hybrid_command( @commands.hybrid_command(
name="unload", name="unload",
@@ -49,16 +62,19 @@ class CogManagement(commands.Cog, name="cog_management"):
""" """
try: try:
await self.bot.unload_extension(f"cogs.{cog}") await self.bot.unload_extension(f"cogs.{cog}")
except Exception: except Exception as e:
embed = discord.Embed( embed = discord.Embed(
description=f"Could not unload the `{cog}` cog.", color=0xE02B2B title="Error",
description=f"Could not unload the `{cog}` cog.\n```{str(e)}```", color=0xE02B2B
) )
await context.send(embed=embed) embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed, ephemeral=True)
return return
embed = discord.Embed( embed = discord.Embed(
description=f"Successfully unloaded the `{cog}` cog.", color=0xBEBEFE description=f"Successfully unloaded the `{cog}` cog.", color=0xBEBEFE
) )
await context.send(embed=embed) embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed)
@commands.hybrid_command( @commands.hybrid_command(
name="reload", name="reload",
@@ -75,16 +91,32 @@ class CogManagement(commands.Cog, name="cog_management"):
""" """
try: try:
await self.bot.reload_extension(f"cogs.{cog}") await self.bot.reload_extension(f"cogs.{cog}")
except Exception: except Exception as e:
embed = discord.Embed( embed = discord.Embed(
description=f"Could not reload the `{cog}` cog.", color=0xE02B2B title="Error",
description=f"Could not reload the `{cog}` cog.\n```{str(e)}```", color=0xE02B2B
) )
await context.send(embed=embed) embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed, ephemeral=True)
return return
embed = discord.Embed( embed = discord.Embed(
title="Cog Management",
description=f"Successfully reloaded the `{cog}` cog.", color=0xBEBEFE description=f"Successfully reloaded the `{cog}` cog.", color=0xBEBEFE
) )
await context.send(embed=embed) embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed)
async def cog_command_error(self, context: Context, error) -> None:
if isinstance(error, commands.NotOwner):
embed = discord.Embed(
title="Error",
description="You are not the owner of the bot!",
color=0xE02B2B
)
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed, ephemeral=True)
else:
raise error
async def setup(bot) -> None: async def setup(bot) -> None: