Dismissed
Dismissed
DIAdiscord.js - Imagine an app
Created by Dismissed on 6/26/2024 in #djs-questions
Bot not reading the correct number of reactions on a message (reads only 1)
No description
5 replies
DIAdiscord.js - Imagine an app
Created by Dismissed on 6/25/2024 in #djs-questions
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')
4 replies
DIAdiscord.js - Imagine an app
Created by Dismissed on 6/25/2024 in #djs-questions
Detect reactions
Hi, I'm trying to simply detect when any reaction has been added to any message. How can I do that? My end goal is to then check if it's in a certain channel before I store it temporarily, so if there's another way to do that that's also fine. I've tried using this code on Collectors just to get started understanding them from https://discordjs.guide/popular-topics/collectors.html#message-collectors but it seems like it needs to be in a command, which i'm not sure where in a command it would be since commands have a short life span and this is a more long (2 day) active thing.
// `m` is a message object that will be passed through the filter function
const collectorFilter = m => m.content.includes('discord');
const collector = interaction.channel.createMessageCollector({ filter: collectorFilter, time: 15_000 });

collector.on('collect', m => {
console.log(`Collected ${m.content}`);
});

collector.on('end', collected => {
console.log(`Collected ${collected.size} items`);
});
// `m` is a message object that will be passed through the filter function
const collectorFilter = m => m.content.includes('discord');
const collector = interaction.channel.createMessageCollector({ filter: collectorFilter, time: 15_000 });

collector.on('collect', m => {
console.log(`Collected ${m.content}`);
});

collector.on('end', collected => {
console.log(`Collected ${collected.size} items`);
});
Any help appreciated! 🙂
4 replies