feat: implement owner check for slash_change_avatar command and improve error handling

This commit is contained in:
Slipstream 2025-05-26 14:52:35 -06:00
parent 61b433360c
commit 195b95d575
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -4,6 +4,11 @@ from discord import app_commands
import httpx
import io
# --- Helper: Owner Check ---
async def is_owner_check(interaction: discord.Interaction) -> bool:
"""Checks if the interacting user is the bot owner."""
return interaction.user.id == interaction.client.owner_id
class BotAppearanceCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@ -63,7 +68,7 @@ class BotAppearanceCog(commands.Cog):
image_url="A direct URL to the image for the new avatar (optional if attachment is provided).",
attachment="An image file to use as the new avatar (optional if URL is provided)."
)
@app_commands.checks.is_owner()
@app_commands.check(is_owner_check)
async def slash_change_avatar(self, interaction: discord.Interaction, image_url: str = None, attachment: discord.Attachment = None):
"""Changes the bot's global avatar. Accepts a direct image URL or an attachment."""
await interaction.response.defer(ephemeral=True)
@ -127,7 +132,7 @@ class BotAppearanceCog(commands.Cog):
async def cog_app_command_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError):
if isinstance(error, app_commands.MissingPermissions):
await interaction.response.send_message("You don't have the required permissions (Administrator) to use this command.", ephemeral=True)
elif isinstance(error, app_commands.NotOwner):
elif isinstance(error, app_commands.CheckFailure):
await interaction.response.send_message("This command can only be used by the bot owner. If you wish to customize your bot's appearance, please set up a custom bot on the web dashboard.", ephemeral=True)
else:
print(f"Error in BotAppearanceCog (app_command): {error}") # Log other errors to console