我正在尝试使用discord.py版本0.16.12添加自定义表情符号作为对消息的反应,但无法使其正常运行。这是我正在使用的代码:
@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函数中找到特定的表情符号对象?
(message, '#EmojiID#')
add_reaction
get_all_emojis
您可以使用实用程序功能discord.utils.get来获取适当的Emoji对象。
discord.utils.get
Emoji
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)