Issue with Fetching User Details from Reactions in Discord.js

Hi! I'm encountering a challenge with retrieving user details from message reactions. Below is a detailed breakdown of my setup and the problem: 1. Discord.js and Node Versions: - Discord.js Version: 14.13.0 - Node Version: 18.18.0 2. Bot Configuration: - My bot is configured with the following intents and partials:
const client = new Client({
intents: [GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMembers, GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages, GatewayIntentBits.DirectMessages],
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
});

const client = new Client({
intents: [GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMembers, GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages, GatewayIntentBits.DirectMessages],
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
});

3. Process Reactions Function: - The processReactions function, which is supposed to fetch reactions and their user details, is defined as:
const processReactions = async (message: Message<boolean>[]) => {
try {
let reactions = await fetchReactionsFromMessage(message);
for (const reaction of reactions) {
await fetchReactionUsers(reaction);
}
} catch (error) {
// Error handling
}
}

const processReactions = async (message: Message<boolean>[]) => {
try {
let reactions = await fetchReactionsFromMessage(message);
for (const reaction of reactions) {
await fetchReactionUsers(reaction);
}
} catch (error) {
// Error handling
}
}

4. Fetch Reaction Users Function: - The fetchReactionUsers function is intended to retrieve users from a given reaction:
export async function fetchReactionUsers(reaction: MessageReaction): Promise<User[]> {
let result: User[] = [];
try {
let users = await reaction.users.fetch();
for (const user of users.values()) {
result.push(user);
}
return result;
} catch (error) {
logger.error(error, `Error fetching reaction users`);
return result;
}
}

export async function fetchReactionUsers(reaction: MessageReaction): Promise<User[]> {
let result: User[] = [];
try {
let users = await reaction.users.fetch();
for (const user of users.values()) {
result.push(user);
}
return result;
} catch (error) {
logger.error(error, `Error fetching reaction users`);
return result;
}
}

5. Issue Description: - Despite this setup, I'm unable to access the user details of the reactions. I successfully get the reactions, but the user information is not being retrieved as expected. 6. Request for Assistance: - I would greatly appreciate any insights or suggestions on resolving this issue. Thank you for your help!
11 Replies
d.js toolkit
d.js toolkit7mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Syjalo
Syjalo7mo ago
What is the issue? What do you expect?
LunarRage | DNA
LunarRage | DNA7mo ago
I was expecting to get users who utilized the reaction.
Syjalo
Syjalo7mo ago
So it returns an empty array?
LunarRage | DNA
LunarRage | DNA7mo ago
yea I can see emoji details and the message id but user array is empty I assumed fetching them manually would populate that array but, still empty
Syjalo
Syjalo7mo ago
Show the code how did you check it's empty
LunarRage | DNA
LunarRage | DNA7mo ago
Oh did I post it incorrectly? I have it broken down in the original post. I essentially logged the contents of the fetchReactionUsers to the logger
export async function fetchReactionUsers(reaction: MessageReaction): Promise<User[]> {
let result: User[] = [];
try {
let users = await reaction.users.fetch();
for (const user of users.values()) {
result.push(user);
}
return result;
} catch (error) {
logger.error(error, `Error fetching reaction users`);
return result;
}
}
export async function fetchReactionUsers(reaction: MessageReaction): Promise<User[]> {
let result: User[] = [];
try {
let users = await reaction.users.fetch();
for (const user of users.values()) {
result.push(user);
}
return result;
} catch (error) {
logger.error(error, `Error fetching reaction users`);
return result;
}
}
Syjalo
Syjalo7mo ago
It should return the users if there're some. Show how did you log it.
LunarRage | DNA
LunarRage | DNA7mo ago
Currently using pino. This is on the MessageReaction object.
users: {
"reaction": {
"messageId": "Hidden-ID",
"me": false,
"users": [],
"count": 1,
"emojiId": {
"animated": null,
"name": "🔥",
"id": null,
"reaction": "🔥",
"identifier": "%F0%9F%94%A5"
}
}
}
users: {
"reaction": {
"messageId": "Hidden-ID",
"me": false,
"users": [],
"count": 1,
"emojiId": {
"animated": null,
"name": "🔥",
"id": null,
"reaction": "🔥",
"identifier": "%F0%9F%94%A5"
}
}
}
Syjalo
Syjalo7mo ago
I don't need the log. I need the code where you logged it and used processReactions or fetchReactionUsers.
LunarRage | DNA
LunarRage | DNA7mo ago
Ah I see what happened, My issue was to iterate over the Collection<string,User> I assume I could just log the full object to the console. This works

if(users){
logger.info(`users found ${users.map((user)=>user.username)}`);
}


if(users){
logger.info(`users found ${users.map((user)=>user.username)}`);
}