您如何让机器人使用自定义表情符号添加反应?

How do you have a bot add a reaction using a custom emoji?

我正在尝试使用 discord.py 版本 0.16.12 添加自定义表情符号作为对消息的反应,但我无法使其正常运行。这是我正在使用的代码:

@bot.event
async def on_message(message):
    if message.content.find(':EmojiName:'):
        await bot.add_reaction(message, '<:EmojiName:#EmojiID#>')

我也试过将表情符号 ID 作为类似于 discord.js (message, '#EmojiID#') 的字符串传递。我应该将表情符号对象传递给 add_reaction 函数吗?如果是这样,我如何从 get_all_emojis 函数中找到特定的表情符号对象?

您可以使用效用函数discord.utils.get to get the appropriate Emoji object

from discord.utils import get

@bot.event
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == bot.user:
        return
    if ':EmojiName:' in message.content:
        emoji = get(bot.get_all_emojis(), name='EmojiName')
        await bot.add_reaction(message, emoji)

没关系,伙计们,我想通了。您必须将表情符号对象本身传递给它。为了后代,这是我最终使用的代码:

async def on_message(message):
if message.content.find(':EmojiName:'):
    for x in client.get_all_emojis():
        if x.id == '#EmojiID#':
            return await client.add_reaction(message, x)