在 Discord.py 中发送/获取应用程序表情符号的 ID

问题描述 投票:0回答:1

不能仅从名称中检索自定义应用程序表情符号吗?

有没有办法获取所有应用程序表情符号并将名称与 ID 进行匹配?

我想几年前有人问过这个问题,但从那以后我就再也没有见过任何东西。

get(bot.emojis, name=emoji_name)

这只是在机器人所在的服务器上检索匹配的表情符号,如果服务器没有匹配,则为 null。

await fetch_application_emojis()
会解决这个问题吗?应该是2.5出。

python discord.py
1个回答
0
投票

不确定discord.py中是否有办法,但我只是使用了这个:

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}
© www.soinside.com 2019 - 2024. All rights reserved.