Search code examples
pythondiscorddiscord.pynextcord

How do i remove a specific user's reaction from a message?


I am making a command that will randomly pick a user from a message's reaction (similar to giveaway command). I tried to add a feature that will remove the chosen user's reaction once the user is chosen by the bot but it didn't work. I am new to the world of discord bot, please help me.

Here are the codes:

@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)

Solution

  • You should read about await remove_reaction(emoji, member) from the official documentation.

    You have to simply specify the member of which remove the reaction.