python - 不和谐中的 on_reaction_add 似乎不起作用

标签 python discord discord.py

@client.event
async def on_reaction_add(reaction, user):
    print('reaction added')

当我添加 react 时,它似乎没有打印“已添加 react ”,我在机器人上线后添加了 react ,但仍然不起作用。 完整代码:

import discord

client = discord.Client()

@client.event
async def on_ready():
   print('logged on!')

@client.event
async def on_reaction_add(reaction, user):
   print('reaction added')

client.run('token_here')

最佳答案

我认为您的问题来自于消息是在您的机器人启动之前发送的。正如 documentation 中所写:

If the message is not found in the internal message cache, then this event will not be called.

您应该使用on_raw_reaction_add ,即使消息不在内部缓存中(因此在机器人启动之前发送),它也可以工作。这将返回 payload包含 id 而不是对象(因此如有必要,请转换它们)。

希望能解决您的问题

关于python - 不和谐中的 on_reaction_add 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59225084/

相关文章:

python - 如何将父类的__init__属性继承到子类的__init__?

python - Python 中的字符是如何编码的?

javascript - 将 URL 存储在 JSON 中并在 JavaScript 中调用

python - 如何给一个命令多个名称?

python - 如果 channel 是私有(private)的,我怎么能得到 "check"呢?

python - 使用 TabularInlines 使 Django-Jet 自动完成

python - Flask 多处理在进程完成之前不会返回响应

javascript - nodejs runMicrotasks() 中的未知内部错误

javascript - 自定义 react 表情符号不和谐 js : "Client undefined"

python - 命令引发异常 : AttributeError: 'str' object has no attribute 'id'