on_reaction_add 仅在机器人最初向消息添加反应时被调用

时间:2021-02-23 20:13:03

标签: python discord.py

我有一些代码

@bot.event
async def on_reaction_add(reaction, user):
    print("hello")
    if(user.id == bot.user.id):
        return
    if(not reaction.message.guild):
        await reaction.message.delete()

@bot.command(name="dm", brief="Anonymously dms user")
async def dm(ctx, user: discord.Member, *, message=None):
    await ctx.message.delete()
    if(message is None):
        await ctx.send("Enter a message to send to this user!")
        return
    msg = await user.send("**An anonymous user sent you this:** "+message)
    await msg.add_reaction("\U0001F5D1")

on_reaction_add 仅在我的机器人最初对其自己的消息添加反应时才被调用。当我尝试向消息添加反应时,hello 不会打印到终端中,也没有任何错误。

编辑:通过使用 on_raw_reaction_add 而不是 on_reaction_add 修复了问题。

1 个答案:

答案 0 :(得分:1)

on_reaction_add() 要求消息位于内部消息缓存中。尝试改用这个:

on_raw_reaction_add(payload)

查看更多信息here