Stuck trying to create a map to track votes on messages

I'm trying to allow user to upvote/downvote messages using reactions, as well remove their previous vote. I'm using a map and a map of maps to do this. The problem is that when a user reacts to a message, the map "userMessageVotes" updates correctly, but the map of maps does not. userMessageVotes - A map of a users votes per message messageVotes - A map of maps that has all votes from all users in a message.
const messageVotes = new Map();

if (currentEmoji === 'šŸ‘' || currentEmoji === 'šŸ‘Ž') {
console.log(`Reaction is šŸ‘ or šŸ‘Ž`);
messageUserVotes.set(user.id, currentEmoji);
messageVotes.set(message.id, messageUserVotes);
console.log(`Updated vote for user ${user.id}: ${reaction.emoji.name}`);

console.log(`New messageUserVotes map for message ${message.id}: ${JSON.stringify(Array.from(messageUserVotes.entries()))}`);
console.log(`New messageVotes map for message ${message.id}: ${JSON.stringify(Array.from(messageVotes.entries()))}`);

} else {
console.log(`Reaction is not šŸ‘ or šŸ‘Ž`);
}

if (currentEmoji === 'šŸ‘' || currentEmoji === 'šŸ‘Ž') {
// Check if the opposite reaction exists
const oppositeEmoji = currentEmoji === 'šŸ‘' ? 'šŸ‘Ž' : 'šŸ‘';
const oppositeReaction = message.reactions.cache.find(r => r.emoji.name === oppositeEmoji);

// If the opposite reaction exists, remove it
if (oppositeReaction) {
await oppositeReaction.users.remove(user.id);
}

// Get previous vote
const previousVote = messageUserVotes.get(user.id) || null;
console.log(`Previous vote for user ${user.id}: ${previousVote}`);

const data = {...
const messageVotes = new Map();

if (currentEmoji === 'šŸ‘' || currentEmoji === 'šŸ‘Ž') {
console.log(`Reaction is šŸ‘ or šŸ‘Ž`);
messageUserVotes.set(user.id, currentEmoji);
messageVotes.set(message.id, messageUserVotes);
console.log(`Updated vote for user ${user.id}: ${reaction.emoji.name}`);

console.log(`New messageUserVotes map for message ${message.id}: ${JSON.stringify(Array.from(messageUserVotes.entries()))}`);
console.log(`New messageVotes map for message ${message.id}: ${JSON.stringify(Array.from(messageVotes.entries()))}`);

} else {
console.log(`Reaction is not šŸ‘ or šŸ‘Ž`);
}

if (currentEmoji === 'šŸ‘' || currentEmoji === 'šŸ‘Ž') {
// Check if the opposite reaction exists
const oppositeEmoji = currentEmoji === 'šŸ‘' ? 'šŸ‘Ž' : 'šŸ‘';
const oppositeReaction = message.reactions.cache.find(r => r.emoji.name === oppositeEmoji);

// If the opposite reaction exists, remove it
if (oppositeReaction) {
await oppositeReaction.users.remove(user.id);
}

// Get previous vote
const previousVote = messageUserVotes.get(user.id) || null;
console.log(`Previous vote for user ${user.id}: ${previousVote}`);

const data = {...
1 Reply
d.js toolkit
d.js toolkitā€¢2y ago
ā€¢ What's your exact discord.js npm list discord.js and node node -v version? ā€¢ Post the full error stack trace, not just the top part! ā€¢ Show your code! ā€¢ Explain what exactly your issue is. ā€¢ Not a discord.js issue? Check out #useful-servers.
Want results from more Discord servers?
Add your server