lexitorius
lexitorius
DIAdiscord.js - Imagine an app
Created by lexitorius on 2/23/2024 in #djs-questions
Reading reaction info
I am attempting to take an array of reactions on a given message and identify the individual users that have posted each reaction. I have run into an issue where I can only reliably console.log the bot's user ID, and the list does not contain the rest of the user IDs unless the command is run immediately following a reaction state change (someone adds one). The other issue I'm running into is that I can console.log the information, but I can't seem to access it programmatically. This line of code is turning the reaction.users circular collection into something I can read in the console.
reactions.forEach(reaction => { if (reaction.count>1) { console.log(JSON.stringify(reaction.users,null,2)); } });
reactions.forEach(reaction => { if (reaction.count>1) { console.log(JSON.stringify(reaction.users,null,2)); } });
Before that line is stringifying the array, this block is trying to read each element of the reactions.users array and console log it:
let userIds= [];
for (const user in reactions.users) {
userIds.push(user);
}
console.log(`Ids: ${userIds}`);
let userIds= [];
for (const user in reactions.users) {
userIds.push(user);
}
console.log(`Ids: ${userIds}`);
This is not working. The console log is returning a list of userIDs in the stringified log, but returning Id: for the block that is trying to get the user IDs. I am not sure what to do or try next, as I've already dug through youtube, guides, and chatGPT
17 replies
DIAdiscord.js - Imagine an app
Created by lexitorius on 2/23/2024 in #djs-questions
Issue reading list of users who have reacted to a message
Afternoon, I'm creating a voting system in one of my servers that has users choose one of eight options. I am currently attempting to get the bot to reliably read the list of users that have reacted to each reaction, while also ignoring its own reactions. Related code
if (victors.length===1) {
thmb = highestCountReactions.map((info) => raidMasterList.find((raid) => raid.emj===info.name)?.icon || info.name);
title = `Raid Vote: ${victors}`;
desc = `${victors} wins with ${highestCountReactions[0].count} votes!`;
} else if (victors.length>1) {
title = `Raid Vote: TIE!`;
desc = `__Raid vote ended in a tie__\n\`-\` ${victors.join('\n\`-\` ')}`
}

const eRaidVote = new EmbedBuilder()
.setTitle(`${title}`)
.setDescription(`${desc}`)
.setColor(0x00ff00)
.setThumbnail(`${thmb}`)

reactions.forEach(reaction => { if (reaction.count>1) { console.log(JSON.stringify(reaction.users,null,2)); } })
//trgtMsg.reactions.removeAll();
await interaction.reply({embeds: [eRaidVote]});
if (victors.length===1) {
thmb = highestCountReactions.map((info) => raidMasterList.find((raid) => raid.emj===info.name)?.icon || info.name);
title = `Raid Vote: ${victors}`;
desc = `${victors} wins with ${highestCountReactions[0].count} votes!`;
} else if (victors.length>1) {
title = `Raid Vote: TIE!`;
desc = `__Raid vote ended in a tie__\n\`-\` ${victors.join('\n\`-\` ')}`
}

const eRaidVote = new EmbedBuilder()
.setTitle(`${title}`)
.setDescription(`${desc}`)
.setColor(0x00ff00)
.setThumbnail(`${thmb}`)

reactions.forEach(reaction => { if (reaction.count>1) { console.log(JSON.stringify(reaction.users,null,2)); } })
//trgtMsg.reactions.removeAll();
await interaction.reply({embeds: [eRaidVote]});
The line in particular is the third from bottom, which is supposed to take all reactions that are greater than 1 (in order to ignore the bot's) and list the users associated with them. When I do let it include itself, it lists the bot's user ID correctly, but it otherwise returns this:
{
"reaction": {
"messageId": "1210638706126626936",
"me": false,
"users": [],
"count": 2,
"emojiId": "1090404643953201234"
}
{
"reaction": {
"messageId": "1210638706126626936",
"me": false,
"users": [],
"count": 2,
"emojiId": "1090404643953201234"
}
I have tried looking up reaction guides on youtube, documentation, and bickering with chatGPT, to no avail. I have all intents enabled so it's not an intent issue
3 replies