【问题标题】:How do i remove a specific user's reaction from a message?如何从消息中删除特定用户的反应?
【发布时间】:2022-01-22 11:55:02
【问题描述】:

我正在创建一个命令,该命令将从消息的反应中随机选择一个用户(类似于赠品命令)。我尝试添加一个功能,该功能将在机器人选择用户后删除所选用户的反应,但它不起作用。我是不和谐机器人世界的新手,请帮助我。

代码如下:

@client.command()
async def king(ctx):
    time = 10
    embed = nextcord.Embed(title="King's Game", description="React to join.")
    embed.set_footer(text=f"Ends in {time}s")
    kmsg = await ctx.send(embed=embed)
    await kmsg.add_reaction("????")

    await asyncio.sleep(time)

    new_msg = await ctx.channel.fetch_message(kmsg.id)
    players = await new_msg.reactions[0].users().flatten()
    players.pop(players.index(client.user))
    print (players)

    king = random.choice(players)
    tembed = nextcord.Embed(title="Time is up!", description="Get ready to obey the king.")
    kembed = nextcord.Embed(title="King", description=f"{king.mention} is the king!")
    await ctx.send(embed=tembed)
    ktime = 2
    await asyncio.sleep(ktime)
    await ctx.send(embed=kembed)
    kingid = get(king.user.id)
    await kmsg.remove_reaction(kingid)

【问题讨论】:

    标签: python discord discord.py nextcord


    【解决方案1】:

    您应该从官方文档中了解await remove_reaction(emoji, member)

    您必须简单地指定移除反应的成员。

    【讨论】:

    • 起初我不太了解文档,但我尝试将其更改为 await kmsg.remove_reaction(emoji="?", member=king) 并且它有效。非常感谢!
    猜你喜欢
    • 2021-05-18
    • 2020-02-21
    • 2021-04-21
    • 2021-06-04
    • 2020-09-13
    • 2020-11-22
    • 2018-11-13
    • 2020-11-10
    • 2017-01-14
    相关资源
    最近更新 更多