refactor: (description) owner command handling && fix colors

Standardized embed colors to Discord blurple (0x7289DA) across all cogs. Refactored owner command modules (say, shutdown, sync) to use a shared send_embed helper and improved error handling for permission checks. Updated botinfo title and improved bot owner/team logging in bot.py. Help command now always lists 'owner' category, removing permission checks from category display.
This commit is contained in:
neoarz
2025-09-16 10:21:36 -04:00
parent 1cc3a32e1d
commit a3f30953f6
10 changed files with 127 additions and 51 deletions

20
bot.py
View File

@@ -205,16 +205,16 @@ class DiscordBot(commands.Bot):
f"Running on: {platform.system()} {platform.release()} ({os.name})" f"Running on: {platform.system()} {platform.release()} ({os.name})"
) )
if self.owner_id: try:
try: app_info = await self.application_info()
owner = await self.fetch_user(self.owner_id) if app_info.team:
self.logger.info(f"Owner found: {owner.name} (ID: {self.owner_id})") self.logger.info(f"Bot owned by team: {app_info.team.name}")
except discord.NotFound: for member in app_info.team.members:
self.logger.warning(f"Owner ID {self.owner_id} not found - owner commands may not work") self.logger.info(f"Team member: {member.name} (ID: {member.id})")
except Exception as e: else:
self.logger.error(f"Error fetching owner: {e}") self.logger.info(f"Bot owner: {app_info.owner.name} (ID: {app_info.owner.id})")
else: except Exception as e:
self.logger.warning("No owner ID set - owner commands will not work") self.logger.error(f"Error fetching application info: {e}")
await self.init_db() await self.init_db()
await self.load_cogs() await self.load_cogs()

View File

@@ -34,7 +34,7 @@ class RockPaperScissors(discord.ui.Select):
bot_choice = random.choice(list(choices.keys())) bot_choice = random.choice(list(choices.keys()))
bot_choice_index = choices[bot_choice] bot_choice_index = choices[bot_choice]
result_embed = discord.Embed(title="Rock Paper Scissors", color=0xBEBEFE) result_embed = discord.Embed(title="Rock Paper Scissors", color=0x7289DA)
result_embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp") result_embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
winner = (3 + user_choice_index - bot_choice_index) % 3 winner = (3 + user_choice_index - bot_choice_index) % 3

View File

@@ -19,7 +19,7 @@ class BotInfo(commands.Cog, name="botinfo"):
:param context: The hybrid command context. :param context: The hybrid command context.
""" """
embed = discord.Embed( embed = discord.Embed(
title="Nyrix Discord Bot", title="Syntrel Discord Bot",
color=0x7289DA, color=0x7289DA,
) )
embed.set_author(name="Bot Information", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp") embed.set_author(name="Bot Information", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")

View File

@@ -35,7 +35,7 @@
# embed = discord.Embed( # embed = discord.Embed(
# title="Message without spoilers", # title="Message without spoilers",
# description=message.content.replace("||", ""), # description=message.content.replace("||", ""),
# color=0xBEBEFE, # color=0x7289DA,
# ) # )
# if spoiler_attachment is not None: # if spoiler_attachment is not None:
# embed.set_image(url=attachment.url) # embed.set_image(url=attachment.url)
@@ -52,7 +52,7 @@
# """ # """
# embed = discord.Embed( # embed = discord.Embed(
# description=f"The ID of {user.mention} is `{user.id}`.", # description=f"The ID of {user.mention} is `{user.id}`.",
# color=0xBEBEFE, # color=0x7289DA,
# ) # )
# await interaction.response.send_message(embed=embed, ephemeral=True) # await interaction.response.send_message(embed=embed, ephemeral=True)
# #

View File

@@ -13,10 +13,7 @@ class Help(commands.Cog, name="help"):
interaction: discord.Interaction, interaction: discord.Interaction,
current: str, current: str,
) -> list[app_commands.Choice[str]]: ) -> list[app_commands.Choice[str]]:
categories = ["general", "fun", "moderation", "template"] categories = ["general", "fun", "moderation", "template", "owner"]
if await self.bot.is_owner(interaction.user):
categories.append("owner")
suggestions = [] suggestions = []
for category in categories: for category in categories:
@@ -85,8 +82,6 @@ class Help(commands.Cog, name="help"):
for cog_name in self.bot.cogs: for cog_name in self.bot.cogs:
mapped_category = category_mapping.get(cog_name.lower()) mapped_category = category_mapping.get(cog_name.lower())
if mapped_category: if mapped_category:
if mapped_category == "owner" and not (await self.bot.is_owner(context.author)):
continue
available_categories.add(mapped_category) available_categories.add(mapped_category)
category_list = [] category_list = []
@@ -120,17 +115,6 @@ class Help(commands.Cog, name="help"):
await context.author.send(embed=embed) await context.author.send(embed=embed)
return return
if category == "owner" and not (await self.bot.is_owner(context.author)):
embed = discord.Embed(
title="Error",
description="You don't have permission to view owner commands.",
color=0x7289DA
)
if context.interaction:
await context.interaction.response.send_message(embed=embed, ephemeral=True)
else:
await context.author.send(embed=embed)
return
commands_in_category = [] commands_in_category = []
seen_names = set() seen_names = set()

View File

@@ -28,7 +28,7 @@ class Ping(commands.Cog, name="ping"):
embed = discord.Embed( embed = discord.Embed(
title="🏓 Pong!", title="🏓 Pong!",
description=f"The bot latency is {round(self.bot.latency * 1000)}ms.", description=f"The bot latency is {round(self.bot.latency * 1000)}ms.",
color=0xBEBEFE, color=0x7289DA,
) )
embed.set_author(name="Ping", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp") embed.set_author(name="Ping", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
if getattr(context, "interaction", None): if getattr(context, "interaction", None):

View File

@@ -42,7 +42,7 @@ class CogManagement(commands.Cog, name="cog_management"):
await self.send_embed(context, embed, ephemeral=True) 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=0x7289DA
) )
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp") embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed) await self.send_embed(context, embed)
@@ -71,7 +71,7 @@ class CogManagement(commands.Cog, name="cog_management"):
await self.send_embed(context, embed, ephemeral=True) 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=0x7289DA
) )
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp") embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed) await self.send_embed(context, embed)
@@ -101,7 +101,7 @@ class CogManagement(commands.Cog, name="cog_management"):
return return
embed = discord.Embed( embed = discord.Embed(
title="Cog Management", title="Cog Management",
description=f"Successfully reloaded the `{cog}` cog.", color=0xBEBEFE description=f"Successfully reloaded the `{cog}` cog.", color=0x7289DA
) )
embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp") embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed) await self.send_embed(context, embed)

View File

@@ -8,6 +8,16 @@ class Say(commands.Cog, name="say"):
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 context.send(embed=embed)
@commands.hybrid_command( @commands.hybrid_command(
name="say", name="say",
description="The bot will say anything you want.", description="The bot will say anything you want.",
@@ -36,8 +46,26 @@ class Say(commands.Cog, name="say"):
:param context: The hybrid command context. :param context: The hybrid command context.
:param message: The message that should be repeated by the bot. :param message: The message that should be repeated by the bot.
""" """
embed = discord.Embed(description=message, color=0xBEBEFE) embed = discord.Embed(
await context.send(embed=embed) title="Say",
description=message,
color=0x7289DA,
)
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="Permission Denied",
description="You are not the owner of this 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:

View File

@@ -6,6 +6,16 @@ from discord.ext.commands import Context
class Shutdown(commands.Cog, name="shutdown"): class Shutdown(commands.Cog, name="shutdown"):
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 context.send(embed=embed)
@commands.hybrid_command( @commands.hybrid_command(
name="shutdown", name="shutdown",
@@ -18,10 +28,27 @@ class Shutdown(commands.Cog, name="shutdown"):
:param context: The hybrid command context. :param context: The hybrid command context.
""" """
embed = discord.Embed(description="Shutting down. Bye! :wave:", color=0xBEBEFE) embed = discord.Embed(
await context.send(embed=embed) title="Shutdown",
description="Shutting down. Bye! <a:PandaThanos:1417483671253811262>",
color=0x7289DA,
).set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp")
await self.send_embed(context, embed)
await self.bot.close() await self.bot.close()
async def cog_command_error(self, context: Context, error) -> None:
if isinstance(error, commands.NotOwner):
embed = discord.Embed(
title="Permission Denied",
description="You are not the owner of this 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:
await bot.add_cog(Shutdown(bot)) await bot.add_cog(Shutdown(bot))

View File

@@ -8,6 +8,16 @@ class Sync(commands.Cog, name="sync"):
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 context.send(embed=embed)
@commands.command( @commands.command(
name="sync", name="sync",
description="Synchonizes the slash commands.", description="Synchonizes the slash commands.",
@@ -24,24 +34,31 @@ class Sync(commands.Cog, name="sync"):
if scope == "global": if scope == "global":
await context.bot.tree.sync() await context.bot.tree.sync()
embed = discord.Embed( embed = discord.Embed(
title="Sync",
description="Slash commands have been globally synchronized.", description="Slash commands have been globally synchronized.",
color=0xBEBEFE, color=0x7289DA,
) )
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)
return return
elif scope == "guild": elif scope == "guild":
context.bot.tree.copy_global_to(guild=context.guild) context.bot.tree.copy_global_to(guild=context.guild)
await context.bot.tree.sync(guild=context.guild) await context.bot.tree.sync(guild=context.guild)
embed = discord.Embed( embed = discord.Embed(
title="Sync",
description="Slash commands have been synchronized in this guild.", description="Slash commands have been synchronized in this guild.",
color=0xBEBEFE, color=0x7289DA,
) )
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)
return return
embed = discord.Embed( embed = discord.Embed(
description="The scope must be `global` or `guild`.", color=0xE02B2B title="Error",
description="The scope must be `global` or `guild`.",
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)
@commands.command( @commands.command(
name="unsync", name="unsync",
@@ -62,24 +79,44 @@ class Sync(commands.Cog, name="sync"):
context.bot.tree.clear_commands(guild=None) context.bot.tree.clear_commands(guild=None)
await context.bot.tree.sync() await context.bot.tree.sync()
embed = discord.Embed( embed = discord.Embed(
title="Unsync",
description="Slash commands have been globally unsynchronized.", description="Slash commands have been globally unsynchronized.",
color=0xBEBEFE, color=0x7289DA,
) )
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)
return return
elif scope == "guild": elif scope == "guild":
context.bot.tree.clear_commands(guild=context.guild) context.bot.tree.clear_commands(guild=context.guild)
await context.bot.tree.sync(guild=context.guild) await context.bot.tree.sync(guild=context.guild)
embed = discord.Embed( embed = discord.Embed(
title="Unsync",
description="Slash commands have been unsynchronized in this guild.", description="Slash commands have been unsynchronized in this guild.",
color=0xBEBEFE, color=0x7289DA,
) )
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)
return return
embed = discord.Embed( embed = discord.Embed(
description="The scope must be `global` or `guild`.", color=0xE02B2B title="Error",
description="The scope must be `global` or `guild`.",
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)
async def cog_command_error(self, context: Context, error) -> None:
if isinstance(error, commands.NotOwner):
embed = discord.Embed(
title="Permission Denied",
description="You are not the owner of this 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: