"""Admin emoji management slash commands.""" import discord from discord.app_commands import Command from discord.ext import commands async def upload_emoji(interaction: discord.Interaction, name: str, file_path: str) -> None: """Upload a custom emoji (JPG, PNG, or GIF) to the guild.""" if not interaction.guild: await interaction.response.send_message( "This command can only be used in a server.", ephemeral=True, ) return if not interaction.guild.permissions_for(interaction.user).manage_emojis_and_stickers: await interaction.response.send_message( "You need manage_emojis_and_stickers permission.", ephemeral=True, ) return try: with open(file_path, "rb") as f: image_bytes = f.read() await interaction.guild.create_custom_emoji(name=name, image=image_bytes) await interaction.response.send_message( f"Successfully uploaded emoji `{name}`!", ephemeral=True, ) except FileNotFoundError: await interaction.response.send_message( "Error: File not found.", ephemeral=True, ) except Exception as e: await interaction.response.send_message( f"Error uploading emoji: {e}", ephemeral=True, ) upload_emoji.__signature__ = None # type: ignore async def list_emojis(interaction: discord.Interaction) -> None: """List all custom emojis in the guild.""" if not interaction.guild: await interaction.response.send_message( "This command can only be used in a server.", ephemeral=True, ) return emojis = await interaction.guild.emojis() emoji_list = [] for emoji in emojis: emoji_list.append(f"👍 `{emoji.name}` (ID: {emoji.id})") if not emoji_list: await interaction.response.send_message( "No custom emojis found in this guild.", ephemeral=True, ) else: await interaction.response.send_message("\n".join(emoji_list), ephemeral=True) list_emojis.__signature__ = None # type: ignore async def delete_emoji(interaction: discord.Interaction, *, name: str) -> None: """Delete a custom emoji.""" if not interaction.guild: await interaction.response.send_message( "This command can only be used in a server.", ephemeral=True, ) return if not interaction.guild.permissions_for(interaction.user).manage_emojis_and_stickers: await interaction.response.send_message( "You need manage_emojis_and_stickers permission.", ephemeral=True, ) return try: emojis = await interaction.guild.emojis() emoji = None for e in emojis: if e.name.lower() == name.lower(): emoji = e break if emoji is None: await interaction.response.send_message( f"Emoji `{name}` not found.", ephemeral=True, ) return await emoji.delete() await interaction.response.send_message( f"Successfully deleted emoji `{name}`!", ephemeral=True, ) except discord.NotFound: await interaction.response.send_message( f"Emoji `{name}` not found.", ephemeral=True, ) except Exception as e: await interaction.response.send_message( f"Error deleting emoji: {e}", ephemeral=True, ) delete_emoji.__signature__ = None # type: ignore