我正在尝试使用 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#>')
我还尝试将表情符号 id 作为类似于 discord.js
(message, '#EmojiID#')
的字符串传递.我应该通过 add_reaction
作用于表情符号对象?如果是这种情况,我如何从 get_all_emojis
中找到特定的表情符号对象功能?
最佳答案
您可以使用实用函数 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)
关于python - 您如何让机器人使用自定义表情符号添加 react ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48982061/