feat: update change_avatar command to restrict usage to bot owner only and enhance error messages

This commit is contained in:
Slipstream 2025-05-26 14:43:03 -06:00
parent 1b0fdb86ca
commit 61b433360c
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -33,8 +33,8 @@ class BotAppearanceCog(commands.Cog):
except Exception as e:
await interaction.response.send_message(f"An error occurred: {e}", ephemeral=True)
@commands.command(name='change_avatar', help="Changes the bot's global avatar. Admin only. Provide a direct image URL.")
@commands.has_permissions(administrator=True)
@commands.command(name='change_avatar', help="Changes the bot's global avatar. Owner only. Provide a direct image URL.")
@commands.is_owner()
async def change_avatar(self, ctx: commands.Context, image_url: str):
"""Changes the bot's global avatar. Requires a direct image URL."""
if not (image_url.startswith('http://') or image_url.startswith('https://')):
@ -63,7 +63,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.has_permissions(administrator=True)
@app_commands.checks.is_owner()
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)
@ -113,6 +113,8 @@ class BotAppearanceCog(commands.Cog):
async def on_command_error(self, ctx: commands.Context, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You don't have the required permissions (Administrator) to use this command.")
elif isinstance(error, commands.NotOwner):
await ctx.send("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.")
elif isinstance(error, commands.MissingRequiredArgument):
await ctx.send(f"Missing required argument: `{error.param.name}`. Please check the command's help.")
else:
@ -125,6 +127,8 @@ 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):
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
if not interaction.response.is_done():