lexitorius
lexitorius
DIAdiscord.js - Imagine a bot
Created by lexitorius on 2/23/2024 in #djs-questions
Reading reaction info
data: new SlashCommandBuilder().setName('cv').setDescription('closes a raid vote').addStringOption(
option => option.setName('id').setDescription('id of vote message').setRequired(true)
),
async execute(interaction) {
const guild = await interaction.client.guilds.fetch(guildId);
const channel = await interaction.channel;
const trgtId = await interaction.options.get('id').value;
const trgtMsg = await channel.messages.fetch(trgtId);
let thmb = 'https://cdn.discordapp.com/emojis/1070246146938773525.webp?size=128&quality=lossless';
let title,desc;
let reactions = trgtMsg.reactions.cache;
let reactionInfoArray = [];

reactions.forEach((reaction) => {
if (reaction.count > 1) {
const reactionInfo = {name: reaction.emoji.name, count: reaction.count - 1};
reactionInfoArray.push(reactionInfo);
}
})
const highestCountReactions = reactionInfoArray.filter((info) => info.count === Math.max(...reactionInfoArray.map((info) => info.count)));
const victors = highestCountReactions.map((info) => raidMasterList.find((raid) => raid.emj===info.name)?.name || info.name);

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}`)

console.log(reaction.users.cache.size);
//reactions.forEach(reaction => { if (reaction.count>1) { console.log(JSON.stringify(reaction.users,null,2)); } });
//trgtMsg.reactions.removeAll();
await interaction.reply({embeds: [eRaidVote]});
}
}
data: new SlashCommandBuilder().setName('cv').setDescription('closes a raid vote').addStringOption(
option => option.setName('id').setDescription('id of vote message').setRequired(true)
),
async execute(interaction) {
const guild = await interaction.client.guilds.fetch(guildId);
const channel = await interaction.channel;
const trgtId = await interaction.options.get('id').value;
const trgtMsg = await channel.messages.fetch(trgtId);
let thmb = 'https://cdn.discordapp.com/emojis/1070246146938773525.webp?size=128&quality=lossless';
let title,desc;
let reactions = trgtMsg.reactions.cache;
let reactionInfoArray = [];

reactions.forEach((reaction) => {
if (reaction.count > 1) {
const reactionInfo = {name: reaction.emoji.name, count: reaction.count - 1};
reactionInfoArray.push(reactionInfo);
}
})
const highestCountReactions = reactionInfoArray.filter((info) => info.count === Math.max(...reactionInfoArray.map((info) => info.count)));
const victors = highestCountReactions.map((info) => raidMasterList.find((raid) => raid.emj===info.name)?.name || info.name);

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}`)

console.log(reaction.users.cache.size);
//reactions.forEach(reaction => { if (reaction.count>1) { console.log(JSON.stringify(reaction.users,null,2)); } });
//trgtMsg.reactions.removeAll();
await interaction.reply({embeds: [eRaidVote]});
}
}
17 replies
DIAdiscord.js - Imagine a bot
Created by lexitorius on 2/23/2024 in #djs-questions
Reading reaction info
reactions is an array of the reaction objects
17 replies
DIAdiscord.js - Imagine a bot
Created by lexitorius on 2/23/2024 in #djs-questions
Reading reaction info
There's more above but not super related
17 replies
DIAdiscord.js - Imagine a bot
Created by lexitorius on 2/23/2024 in #djs-questions
Reading reaction info
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}`)

console.log(reaction.users.cache.size);
//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}`)

console.log(reaction.users.cache.size);
//reactions.forEach(reaction => { if (reaction.count>1) { console.log(JSON.stringify(reaction.users,null,2)); } });
//trgtMsg.reactions.removeAll();
await interaction.reply({embeds: [eRaidVote]});
}
}
17 replies
DIAdiscord.js - Imagine a bot
Created by lexitorius on 2/23/2024 in #djs-questions
Reading reaction info
Will look into reactionusermanager might have to watch some tutorial vids tho lol
17 replies
DIAdiscord.js - Imagine a bot
Created by lexitorius on 2/23/2024 in #djs-questions
Reading reaction info
TypeError: Cannot read properties of undefined (reading 'cache')
at Object.execute (C:\Users\mfros\js-proj
ects\ablazedglory\commands\server-events\cv.js:45:37)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (C:\Users\mfros\js-projects\ablazedglory\index.js:245:8)
TypeError: Cannot read properties of undefined (reading 'cache')
at Object.execute (C:\Users\mfros\js-proj
ects\ablazedglory\commands\server-events\cv.js:45:37)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (C:\Users\mfros\js-projects\ablazedglory\index.js:245:8)
17 replies
DIAdiscord.js - Imagine a bot
Created by lexitorius on 2/23/2024 in #djs-questions
Reading reaction info
But yeah it’s not throwing any errors, just returning an empty list
17 replies
DIAdiscord.js - Imagine a bot
Created by lexitorius on 2/23/2024 in #djs-questions
Reading reaction info
I will check on mark’s question in a bit
17 replies
DIAdiscord.js - Imagine a bot
Created by lexitorius on 2/23/2024 in #djs-questions
Issue reading list of users who have reacted to a message
Nevermind, it has all of a sudden decided to start working correctly even though I didn't change anything in the code
3 replies