Discord.js: Get user reactions without the message event

Created on 11 Aug 2020  路  4Comments  路  Source: discordjs/discord.js

I would like to request a feature similar to
client.channels.get([channel id])
but a bit more in depth.

I need to retrieve a collection of users that have reacted to a specific message that is being tracked through it's ID. This is done through cron though and with cron functions I have noticed that there are some limitations, which I understand, but I have all the data required to pull the specific emoji. An example would be like
client.channels.get[channel id].messages.get[message id].reactions.get[reaction snowflake]
This could return a list of users that have reacted to the emoji and per user you get their default data such as username and user ID and maybe some emoji data.
Message itself could return some message related data such as, reactions, user that posted it etc.

Now with this there would be a possible issue, every time someone just tries to get the channel information, it would give them a ton of data.

So a more efficient way might be something along the lines of this
client.messages.get[channel id, message id]
and
client.reactions.get[channel id, message id, reaction snowflake]
Both would return to the user data related to the request. For example message returns message info, the info of the user that posted it and then a list of reactions (name + snowflake).
Reactions would return a list of users that reacted to it with their basic info (name + id).

Currently it is possible to retrieve similar results, but only if an user would use a command, through which the bot could go through the cached data or other roundabout methods. But those don't work through cron. That's why it would be great if message and reactions would also be implemented in a similar way as channels for the API.

In case it already being possible I would love to get some information on how, because I have been stuck on this for a while now.

enhancement

Most helpful comment

Just from a design standpoint:

Something like client.messages.get or client.reactions.get would make no sense in the current approach this library takes. Not to mention the almost arbitrary choice of arguments that are being passed here.

Currently it is very "OOP"-style structured with regards to how the Discord API itself is structured, like no messages without a channel hence no client.messages, no reactions without a message hence no client.reactions etc.

I feel randomly attaching functions like that, that take arbitrary arguments, to the client is not the correct approach here.

All 4 comments

you could achieve this by using partials, enabling the REACTION and MESSAGE partials will allow you to receive messageReactionAdd or messageReactionRemove events on uncached messages - alternatively you can fetch the message using its ID

<TextChannel>.messages.fetch(...)
  .then(message => message.reactions.users.cache.get(...));

Just from a design standpoint:

Something like client.messages.get or client.reactions.get would make no sense in the current approach this library takes. Not to mention the almost arbitrary choice of arguments that are being passed here.

Currently it is very "OOP"-style structured with regards to how the Discord API itself is structured, like no messages without a channel hence no client.messages, no reactions without a message hence no client.reactions etc.

I feel randomly attaching functions like that, that take arbitrary arguments, to the client is not the correct approach here.

Sorry for the late reply, was very occupied unfortunately and had to look more into raw events. I want to clarify that this

you could achieve this by using partials, enabling the REACTION and MESSAGE partials will allow you to receive messageReactionAdd or messageReactionRemove events on uncached messages - alternatively you can fetch the message using its ID

Was the correct solution. It took some time to understand what the raw events was about, but right now everything is working as originally intended.

For those facing similar issues and wanting to read some documents on it to get the general idea behind raw events:
https://anidiots.guide/coding-guides/raw-events

There is a lot more to it as well, it is definitely one of the more interesting things I have encountered with the API so far.

Thank you for the solution!

Discord.js v12 has feature called partials that aims to do exactly that, without the need to use any raw events.
Allows to receive events for uncached structures.
https://discord.js.org/#/docs/main/stable/topics/partials
https://discordjs.guide/popular-topics/partials.html

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BrandonCookeDev picture BrandonCookeDev  路  3Comments

DatMayo picture DatMayo  路  3Comments

LLamaFTL picture LLamaFTL  路  3Comments

tiritto picture tiritto  路  3Comments

shukriadams picture shukriadams  路  3Comments