How do you have a Discord bot remove a user reaction to a message in discord.py?

22,142

You can use either Message.remove_reaction or Reaction.remove.

A Reaction object represents a specific emoji reaction to a Message, so if the Reaction object you have is not for the emoji reaction that you want to remove, using Reaction.remove will attempt to remove the wrong emoji reaction.

Share:
22,142

Related videos on Youtube

Charlie Watson
Author by

Charlie Watson

Updated on July 09, 2022

Comments

  • Charlie Watson
    Charlie Watson almost 2 years

    I'm using an @client.event and using async def on_raw_reaction_add(payload): to read Discord reaction events. I need to be able to delete a user reaction when they fail one of the flags in my code. I saw in the documentation that there is await remove(user) but I don't think I'm using it right. Any suggestions?

  • Charlie Watson
    Charlie Watson over 4 years
    When i try to use the msg id I get from the on_raw_reaction_add payload, it tells me that "int" has no attribute "remove_reaction" and when I use "Message" it tells me that Message isn't defined which I get, here is the code which i will simplify '@client.event async def on_raw_reaction_add(payload) . . . elif banned == 1: await Message.remove_reaction(payload.emoji.name , payload.user_id)'
  • Harmon758
    Harmon758 over 4 years
    Message IDs are integers, not discord.Message objects, so of course they won't have remove_reaction methods. You need to get an instance of discord.Message and define it as Message, if that's what you want to call it. You can do so with the message ID, e.g. via TextChannel.fetch_message. In the future, you should provide all the relevant code and the full traceback when asking for help.
  • Charlie Watson
    Charlie Watson over 4 years
    Thanks, I just figured that out as you commented that, also im getting an error where its saying that my int object has no attribute id, which is the payload.user_id, is there another way to grab the user id?
  • Harmon758
    Harmon758 over 4 years
    Again, IDs are integers. That includes user IDs as well. You already have the user ID. That's what RawReactionActionEvent.user_id is..
  • Harmon758
    Harmon758 over 4 years
    As the documentation for Message.remove_reaction says, the member that's passed must represent a member and meet the Snowflake ABC. This is not the case for an integer representing the ID of a user.
  • Charlie Watson
    Charlie Watson over 4 years
    How would I go about getting the member then?
  • Charlie Watson
    Charlie Watson over 4 years
    nvm i figured it out, I needed to use guild.fetch_members(payload.user_id), thx so much for the help and your time!
  • Harmon758
    Harmon758 over 4 years
    You should take a look at the How do I get a specific model? section of the FAQ. Since you're only retrieving one Member object, there's no reason to use Guild.fetch_members rather than Guild.fetch_member.
  • Harmon758
    Harmon758 over 4 years
    In fact, there's no reason to use an HTTP/API request at all here, unless you've set fetch_offline_members to False when initializing your Client, as the member will be in the user cache and in Guild.members, and thus retrievable simply with Guild.get_member.