Closed sojohnnysaid closed 4 years ago
I am not quite sure what you mean, because the event does in fact pass the reaction (see 11.6.2 docs). As for the users, you can get it from the MessageReaction object passed in.
I mean to say, when listening for someone adding a reaction, I can use the user that gets passed to the callback (messageReactionAdd pass both reaction and user)
So in my case I need to know who is coming and going so I can update the embed.
I'm struggling to figure out a way to get the user who is leaving. messageReactionRemoveEmoji only passes the reaction
Hope that makes sense. If there is something I am overlooking I apologize.
messageReactionRemoveEmoji means all users were removed lol, the users who left (were removed) are the ones included in the reaction
ohhh lol
Any idea how best to accomplish what i'm after in version 11? Am I using the wrong event then?
(if someone clicks an emoji to remove themselves, I can get access to that user and do stuff)
It sounds to me like you want messageReactionRemove instead, which emits when a user removes their reaction from a cached message
Thank you! I will try that. Now I have to nudge repl to update node to V12 =)
How long before a message is cached?
Its not a question of how long, its a question of what you are doing with channels, new messages will be cached and fetched messages will be cached, but there is a possibility of them being sweeped, if you want to get rid of that behavior you can set messageCacheMaxSize to -1 in the client options, however you will have to sweep yourself or your memory usage will climb. It is overall easier and better to use Partials with v12.
Oh I see. I've tried using the messageReactionRemove event before but for some reason it doesn't respond. messageReactionAdd always works so I guess that is a caching issue.
Yes the raw event is a thing, but its not reccomended. it is undocumented and unsupported. You can use it but at your own risk ⚠️
I just wanted to add that I got it working by checking for the cached message ONLY in the add event not the remove ( I think there is something weird going on ). I'm on version 11 of discord js and node 10.
Here is what worked:
Client.on('raw', (response) => {
// guard
if (!['MESSAGE_REACTION_ADD', 'MESSAGE_REACTION_REMOVE'].includes(response.t)) return
const channel = Client.channels.get(response.d.channel_id)
channel.fetchMessage(response.d.message_id).then(message => {
// Emojis can have identifiers of name:id format, so we have to account for that case as well
const emoji = response.d.emoji.id ? `${response.d.emoji.name}:${response.d.emoji.id}` : response.d.emoji.name
// This gives us the reaction we need to emit the event properly, in top of the message object
const reaction = message.reactions.get(emoji)
// Adds the currently reacting user to the reaction's users collection.
if (reaction) reaction.users.set(response.d.user_id, Client.users.get(response.d.user_id))
// Check which type of event it is before emitting
if (response.t == 'MESSAGE_REACTION_ADD') {
if (channel.messages.has(response.d.message_id)) return
Client.emit('messageReactionAdd', reaction, Client.users.get(response.d.user_id))
}
if (response.t == 'MESSAGE_REACTION_REMOVE') {
Client.emit('messageReactionRemove', reaction, Client.users.get(response.d.user_id))
}
})
})
Is your feature request related to a problem? Please describe. I work with a few people remotely. We share our environment using repl.it This allows us to spin up our workstations and do stuff together FAST.
but repl.it isn't ready for node V12 yet so we're on 10. We aren't able to use the latest version of d.js
Specifically it is really painful dealing with the messageReactionRemoveEmoji because the event doesn't pass the reaction AND the user like messageReactionAdd
Describe the ideal solution patch 11 so updating the state of an embed based on reactions is easier
Describe alternatives you've considered patch 11 so messageReactionRemoveEmoji passes the user as well as the reaction
Additional context This library is amazing thank you for such a great tool =)