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

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

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

最佳答案

您可以使用实用程序函数 discord.utils.get 来获取适当的 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)

10-07 19:11
查看更多