Failing to get message.reactions.cache "undefined"

Hi, I'm trying to understand why this code is giving me an errror:
await interaction.deferReply({ ephemeral: true });

//Collect Upvotes/individual rankings
const x = 0;
let messageReacted;
for (const msgID of UpvoteContainer.msgID){
//fetch message(s) of ID UpvoteContainer.msgID
messageReacted = interaction.client.channels.cache.get(interaction.channelId).messages.fetch(msgID);
//const messageReacted = client.channels.cache.get('channelId').messages.fetch('messageId')
console.log("messageReacted achievd");
//For Each Reaction on the message(s)
ERROR ==> await messageReacted.reactions.cache.forEach(async(reaction) => { <== ERROR
//const emojiName = reaction._emoji.name
//const emojiCount = reaction.count
//const reactionUsers = await reaction.users.fetch();
if (reaction.emoji.id == UpvoteContainer.emojiUpvoteID){
x += reaction.count;
}
else if (reaction.emoji.id == UpvoteContainer.emojiDownvoteID){
x =- reaction.count;
}
});
}
await interaction.deferReply({ ephemeral: true });

//Collect Upvotes/individual rankings
const x = 0;
let messageReacted;
for (const msgID of UpvoteContainer.msgID){
//fetch message(s) of ID UpvoteContainer.msgID
messageReacted = interaction.client.channels.cache.get(interaction.channelId).messages.fetch(msgID);
//const messageReacted = client.channels.cache.get('channelId').messages.fetch('messageId')
console.log("messageReacted achievd");
//For Each Reaction on the message(s)
ERROR ==> await messageReacted.reactions.cache.forEach(async(reaction) => { <== ERROR
//const emojiName = reaction._emoji.name
//const emojiCount = reaction.count
//const reactionUsers = await reaction.users.fetch();
if (reaction.emoji.id == UpvoteContainer.emojiUpvoteID){
x += reaction.count;
}
else if (reaction.emoji.id == UpvoteContainer.emojiDownvoteID){
x =- reaction.count;
}
});
}
The error: TypeError: Cannot read properties of undefined (reading 'cache')
3 Replies
d.js toolkit
d.js toolkit•4mo 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
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Dismissed
Dismissed•4mo ago
THANK YOU
Want results from more Discord servers?
Add your server