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.
Related videos on Youtube
![Charlie Watson](https://lh6.googleusercontent.com/-hxyxOC06nNQ/AAAAAAAAAAI/AAAAAAAAAAc/zRdGQGXaFgs/photo.jpg?sz=256)
Author by
Charlie Watson
Updated on July 09, 2022Comments
-
Charlie Watson almost 2 years
I'm using an
@client.event
and usingasync 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 isawait remove(user)
but I don't think I'm using it right. Any suggestions? -
Charlie Watson over 4 yearsWhen 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 over 4 yearsMessage IDs are integers, not
discord.Message
objects, so of course they won't haveremove_reaction
methods. You need to get an instance ofdiscord.Message
and define it asMessage
, if that's what you want to call it. You can do so with the message ID, e.g. viaTextChannel.fetch_message
. In the future, you should provide all the relevant code and the full traceback when asking for help. -
Charlie Watson over 4 yearsThanks, 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 over 4 yearsAgain, IDs are integers. That includes user IDs as well. You already have the user ID. That's what
RawReactionActionEvent.user_id
is.. -
Harmon758 over 4 yearsAs the documentation for
Message.remove_reaction
says, themember
that's passed must represent a member and meet theSnowflake
ABC. This is not the case for an integer representing the ID of a user. -
Charlie Watson over 4 yearsHow would I go about getting the
member
then? -
Charlie Watson over 4 yearsnvm i figured it out, I needed to use
guild.fetch_members(payload.user_id)
, thx so much for the help and your time! -
Harmon758 over 4 yearsYou 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 useGuild.fetch_members
rather thanGuild.fetch_member
. -
Harmon758 over 4 yearsIn fact, there's no reason to use an HTTP/API request at all here, unless you've set
fetch_offline_members
toFalse
when initializing your Client, as the member will be in the user cache and inGuild.members
, and thus retrievable simply withGuild.get_member
.