discord.py在运行机器人程序后未检测到消息的onreaction事件



每当我们向在bot启动之前发送的消息添加反应时,它都不会被检测到。有什么修复方法吗?

代码:(与问题无关(

@client.event
async def on_reaction_add(reaction, user):
if not user.bot:
if reaction.message.author.id == bot_id:
global reactions
if f'{reaction}' in reactions:
await VoteAdded(reaction, user)
await reaction.message.remove_reaction(reaction, user)
else:
await reaction.message.remove_reaction(reaction, user)

这是因为on_reaction_add函数只检查机器人缓存中的消息。

要解决此问题,请将on_reaction_add更改为on_raw_reaction_add

@client.event
async def on_reaction_add

关于reaction_add事件,discord.py documentation说:

[…]如果在内部消息缓存中找不到消息,则不会调用此事件。请考虑改用on_raw_reaction_add()

这样做可能会解决您的问题。

最新更新