I'm using DiscordJs V12.3.1 and I'm trying to return a list of users that have reacted to an old message. (One that was created before the bot was started).
In my current implementation, I get the fetch the message by ID, map through all reactions, then fetch the reaction, and finally map through the users in the reaction.
let cacheChannel = msg.guild.channels.cache.get(channelID);
if(cacheChannel){
cacheChannel.messages.fetch(messageID).then(reactionMessage => {
reactionMessage.reactions.cache.map(async function(reaction){
reaction.fetch().then(r => {
r.users.cache.map(item => {
if(!item.bot) console.log(item.id);
})
})
});
});
}
The above code works for any reactions that were made since the bot started, however fails to find and users that reacted to the message before the bot was started.
Is there a better way to go about this?
Thanks in advance.
EDIT: Updated the above code based on Lioness100's comment
EDIT2: Managed to get it working with resolve(), see answer below
Right, managed to get it working with the use of .resolve() rather than fetching or mapping through the cache.
var getReactedUsers = async(msg, channelID, messageID, emoji) => {
let cacheChannel = msg.guild.channels.cache.get(channelID);
if(cacheChannel){
cacheChannel.messages.fetch(messageID).then(reactionMessage => {
reactionMessage.reactions.resolve(emoji).users.fetch().then(userList => {
return userList.map((user) => user.id)
});
});
}
}
Hopefully that is helpful if anyone has the same issue. (Note: You have to pass the emoji, but you can retrieve a list of reacted emojis by using the method posted in the question or in Lioness' comment)
And thanks to Lioness100 for your responses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With