首页 > 解决方案 > 如何让不和谐机器人使用 discord.py 向消息添加表情符号反应?

问题描述

我一直在尝试获得一个可以使用默认表情符号自动对消息做出反应的不和谐机器人,我不断收到错误代码 10014:找不到表情符号。这是我的代码:

elif message.content == "test":
    await message.add_reaction(:white_check_mark:)

我正在使用 discord api,并且机器人的所有其他部分,例如发送和阅读消息都可以正常工作,但表情符号是我唯一无法弄清楚的事情。

标签: pythondiscord

解决方案


https://discordpy.readthedocs.io/en/latest/api.html?highlight=reaction#discord.Message.add_reaction

表情符号可能是 unicode 表情符号或自定义公会表情符号。

Unicode 表情符号:

await message.add_reaction("✅")

或者通过 Emoji 对象:

https://discordpy.readthedocs.io/en/latest/api.html?highlight=reaction#discord.Client.get_emoji

emoji = client.get_emoji(123456)
await message.add_reaction(emoji)

推荐阅读