如何让不和谐机器人使用 discord.py 向消息添加表情符号反应?

Posted

技术标签:

【中文标题】如何让不和谐机器人使用 discord.py 向消息添加表情符号反应?【英文标题】:How do I get a discord bot to add an emoji reaction to a message using discord.py? 【发布时间】:2020-06-29 09:40:23 【问题描述】:

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

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

我正在使用 discord api,机器人的所有其他部分(例如发送和阅读消息)都可以正常工作,但表情符号是我似乎唯一想不通的东西。

【问题讨论】:

【参考方案1】:

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)

【讨论】:

以上是关于如何让不和谐机器人使用 discord.py 向消息添加表情符号反应?的主要内容,如果未能解决你的问题,请参考以下文章