简体   繁体   中英

How do I remove a reaction from a message by a specific user in Discord.js?

I'd like to remove a reaction from a specific user for a message I've fetched. However I couldn't get it to work (probably because I'm a weeb who can't do Javascript), so it'd be nice if I could get some help:)

I tried looking around such as [this] Remove a users reaction from fetchMessage? - Discord JS thread, however it returned as map was undefined.

The most recent I came up with was this:

            var messageEmbed = message.channel.fetchMessage('637189841418846208')
                .catch(console.error);
                messageEmbed.reactions.remove(message.author.id)

I want it to remove the reaction but instead I got the error "UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'remove' of undefined"

"reactions" is a collection of reactions, therefore you need to first find the specific reaction you are looking for, this example fetches the first reaction on the message and attempts to remove a user from the reaction.

let messageEmbed = message.channel.fetchMessage('637189841418846208')
.catch(console.error);
messageEmbed.reactions.first().remove(message.author.id)

There are many other ways to search within a collection for a specific reaction, a general one is the.get() method witch in this case will search for the reaction based on it's ID

messageEmbed.reactions.get("REACTION ID")

To see all of the methods available see, Collection , Reaction .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM