import discord, aiohttp, re from discord.ext import commands class EmojiCommands(commands.Cog): def __init__(self, bot): self.bot = bot @commands.hybrid_command() async def steal(self, ctx, *, input: str = None): if input.startswith('<:') and input.endswith('>'): emoji_matches = re.findall(r'<:\w+:\d+>', input) if emoji_matches: emoji_str = emoji_matches[0] emoji_id = int(emoji_str.split(':')[2].strip('>')) emoji = discord.PartialEmoji(name=emoji_str.split(':')[1], id=emoji_id) else: return await ctx.send("Invalid emoji format.") elif input.startswith('http://') or input.startswith('https://'): emoji_url = input emoji_name = 'custom_emoji' elif ctx.message.reference and not input: ref_msg = await ctx.fetch_message(ctx.message.reference.message_id) emoji_matches = re.findall(r'<:\w+:\d+>', ref_msg.content) if emoji_matches: emoji_str = emoji_matches[0] emoji_id = int(emoji_str.split(':')[2].strip('>')) emoji = discord.PartialEmoji(name=emoji_str.split(':')[1], id=emoji_id) emoji_url = emoji.url else: await ctx.send("No emoji found to steal in the referenced message.") return else: await ctx.send("Please provide a valid emoji or image URL.") return async with aiohttp.ClientSession() as session: async with session.get(emoji_url) as response: if response.status == 200: data = await response.read() await ctx.guild.create_custom_emoji(name=emoji_name, image=data) await ctx.send(f'Emoji added: {emoji_name}') else: await ctx.send(f'Failed to add emoji. Status code: {response.status}') async def setup(bot): await bot.add_cog(EmojiCommands(bot))