I am working on an advanced Discord Bot. A couple of functionalities work through cron jobs. A new feature I am working on requires the bot to get a collection of users that reacted to a specific message with a specific emoji. Based on that the users will get a temporal role (which most likely possesses the same kind of issue since the documentation for it is identical to the current issue).
I have every data required in order to pull the specific message and possibly it's contents, I however don't know how to access it through cron.
I have the discord server ID, discord channel ID, discord message ID and the emoji snowflake. So theoretically I should be able to access all its contents through the API. However, I noticed that most functionalities are through cached data, and only when an event happens.
A similar cron job that it does is sending a daily overview to a specific channel where it is enabled.
client.channels.get([channel id]).send([formatted data]);
With this functionality, I would however need to get a message and either a collection of all the users that reacted with (ideally) the emoji snowflake.
It has to be through the cron, using a discord command for this is a no go as automation is the key. It should also work without any cached data (where the real issue is). Once again, I have all the data required to pull the message and find the emoji based on snowflake, I just don't know how to do it through cron. The bot also has all the required permissions on the servers that it operates on.
Any pointers or solutions would be appreciated.
The current code in the cronjob:
(async () => {
// walk through channels in DB
var channels = await query([query]);
for (var i = 0; i < channels.length; i++) {
var serv_channel_id = channels[i].server_channel_id;
var disc_channel_id = channels[i].discord_channel_id;
var disc_server_id = channels[i].discord_server_id;
// walk through messages in DB
var messages = await query([query]);
for (var j = 0; j < messages.length; j++) {
var serv_message_id = messages[i].server_message_id;
var disc_message_id = messages[i].discord_message_id;
// walk through reactions in DB
var reactions = await query([query]);
for (var k = 0; k < reactions.legnth; k++) {
var serv_reaction_id = reactions[i].server_react_id;
var r_to_give = reactions[i].role_to_give;
// get discord list of users that reacted with emoji
// check per user if they have the role, if they dont then assign role
}
}
}
})();
Working is currently more important than efficiency. I have left out the queries for obvious reasons and they are not necessary information for this question.