Epic Speedy
Epic Speedy

Reputation: 714

Remove a users reaction from fetchMessage? - Discord JS

I have a question for Discord.js. How would I remove a specific user's reaction from a message?

I have tried to do so with this code:

// Now known as 'messages.fetch'.
message.channel.fetchMessage(MessageID).then(m => {
   m.reactions.remove(UserID);
});

But it doesn't remove the user's reaction at all. Am I doing something wrong?

Any help would be appreciated.

Upvotes: 1

Views: 27070

Answers (4)

Epic Speedy
Epic Speedy

Reputation: 714

Since this question is getting a lot of attraction, I decided to post what worked for me

Remove Specific User's Specific Reaction

// Channel = the channel object of the message's original channel
// MessageID = ID of the message, if hard coding, put around quotations eg: "1234"

const msg = await channel.messages.fetch(MessageID);

msg.reactions.resolve("REACTION EMOJI, 
REACTION OBJECT OR REACTION ID").users.remove("ID OR OBJECT OF USER TO REMOVE");

Note: If using an older version of discord.js, simply replace channel.messages.fetch with channel.fetchMessage

Upvotes: 11

Juan Pablo
Juan Pablo

Reputation: 71

The chosen option works, I would like to explain it. You need to grab the MessageReaction object from the message for the reaction you want to remove. How you do that depends on your code, in my case I was working with a reaction collector so on my collect call I already had the MessageReaction.

You then need to access the users property (a ReactionUserManager object). With this object, you can call .remove().

Code is below:

collector.on('collect', async (reaction, user) => {
...
// delete the reaciton
reaction.users.remove(user.id);
});

Upvotes: 4

barro32
barro32

Reputation: 2708

message.reactions is a collection of messageReactions. I think you need to loop through the collection and then remove the messageReaction required.

message.channel.fetchMessage(messageID).map(r => r).then(message => {
  message.reactions.forEach(reaction => reaction.remove(UserID))
})

Upvotes: 1

yaas
yaas

Reputation: 144

If you look at the documentation for reactions you can see it is a Collection, and it mentions that they are mapped by reaction ID's , and not the user ID's. The way you could remove them is get the reaction, filter the users and then maybe do something with that? I'm not sure how to remove those specifically, but that should get you the users, then filter that to the ID you want.

message.channel.fetchMessage(messageID).then(msg = m.reactions.get(reactionID).users); // Gets the users that reacted to a certain emote, I think.

Upvotes: 0

Related Questions