Search code examples
pythondiscord.py

Sending/Getting ID of Application Emojis in Discord.py


Can you not retrieve custom app emojis from the name alone?

Is there a way to fetch all application emojis and match the name to the ID?

I think someone asked this few years ago, but I haven't seen anything since.

get(bot.emojis, name=emoji_name)

This just retrieves matching emojis on the servers the bot's on, null if there's no match from a server.

Will await fetch_application_emojis() fix this? It's supposed to be out at 2.5.


Solution

  • Not sure if there's a way in discord.py but I just used this:

    CUSTOM_EMOJIS = {}
    
    async def fetch_application_emojis():
        global CUSTOM_EMOJIS
        async with aiohttp.ClientSession() as session:
            async with session.get(f"https://discord.com/api/v10/applications/{app_id}/emojis", 
                                   headers={f"Authorization": "Bot {app_secret}"}) as resp:
                if resp.status == 200:
                    emojis_response = await resp.json()
                    emojis = emojis_response.get("items", [])
                    CUSTOM_EMOJIS = {emoji['name']: int(emoji['id']) for emoji in emojis}