ia_bot/commands/admin.py
Benjamyn 43ca943cb8 feat: A.B.I.N.A.S.H Discord bot with GIF emotes, slash commands, and music
- Core bot with slash command tree (discord.py 2.7.x compatible)
- Commands: /ping, /info, /hello, /emoji, /app-emoji
- Admin: /upload-emoji, /list-emojis, /delete-emoji
- GIF emote detection and reaction handling
- Message reactions with percentage-based triggers and cooldowns
- Voice/music cog with YTDLSource, skip, volume, pause, resume, stop
- Global error handler and voice state change logging
- Environment config via .env (DISCORD_TOKEN, COMMAND_PREFIX, etc.)
2026-08-27 16:05:27 +10:00

122 lines
3.6 KiB
Python

"""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