如何从消息中删除特定用户的反应?
How do i remove a specific user's reaction from a message?
我正在制作一个命令,该命令将从消息的反应中随机选择一个用户(类似于赠品命令)。我试图添加一个功能,一旦用户被机器人选择,该功能将删除所选用户的反应,但它没有用。我是discord bot世界的新手,请帮助我。
代码如下:
@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)
您应该从官方文档中了解 await remove_reaction(emoji, member)
。
您只需指定删除反应的成员。
我正在制作一个命令,该命令将从消息的反应中随机选择一个用户(类似于赠品命令)。我试图添加一个功能,一旦用户被机器人选择,该功能将删除所选用户的反应,但它没有用。我是discord bot世界的新手,请帮助我。
代码如下:
@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)
您应该从官方文档中了解 await remove_reaction(emoji, member)
。
您只需指定删除反应的成员。