Trying to pull users who reacted to a specified message with a specified emoji, need some guidance

Here's my code, can't seem to get reactedUsers to populate with the right values. This makes it a map with 0 length. Is there anything obvious I'm missing here?
async execute(interaction) {
await interaction.deferReply();
var message = await interaction.channel.messages.fetch(
interaction.options.getString("targetmessage")
);

var reactedUsers = await message.reactions.resolve(":poop:").users.cache;

var winner = reactedUsers[Math.random(reactedUsers.count() - 1)];

await interaction.editReply(
`${winner.displayName} is the winner of the giveaway!`
);
},
async execute(interaction) {
await interaction.deferReply();
var message = await interaction.channel.messages.fetch(
interaction.options.getString("targetmessage")
);

var reactedUsers = await message.reactions.resolve(":poop:").users.cache;

var winner = reactedUsers[Math.random(reactedUsers.count() - 1)];

await interaction.editReply(
`${winner.displayName} is the winner of the giveaway!`
);
},
20 Replies
d.js toolkit
d.js toolkit8mo 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 staff
Madder
MadderOP8mo ago
sorry, [email protected] node 17.5.0
kotek
kotek8mo ago
💩
Madder
MadderOP8mo ago
It is the Unicode character in the code, but discord translated it to :poop: when I pasted it into Discord for the help ticket for instance, this doesn't work either:
async execute(interaction) {
var message = interaction.channel.messages.fetch(
interaction.options.getString("targetMessage")
);

var reactedUsers = message.reactions.cache.filter((reaction) => {
reaction.emoji.id === interaction.options.getString("entryEmoji");
}).users.cache;

var winner = reactedUsers[Math.random(reactedUsers.count() - 1)];

await interaction.reply(`${winner.displayName} is the winner of the giveaway!`);
},
async execute(interaction) {
var message = interaction.channel.messages.fetch(
interaction.options.getString("targetMessage")
);

var reactedUsers = message.reactions.cache.filter((reaction) => {
reaction.emoji.id === interaction.options.getString("entryEmoji");
}).users.cache;

var winner = reactedUsers[Math.random(reactedUsers.count() - 1)];

await interaction.reply(`${winner.displayName} is the winner of the giveaway!`);
},
Fixed that issue, now running into a new one with reactedUsers being undefined
async execute(interaction) {
let messageOption = await interaction.options.getString("targetmessage");
let emojiOption = await interaction.options.getString("entryemoji");

var message = await interaction.channel.messages.fetch(messageOption);

var reactedUsers = await message.reactions.cache.filter((reaction) => {
reaction.emoji.name == emojiOption;
}).users;

var winner = reactedUsers[Math.random(reactedUsers.count() - 1)];

await interaction.reply(
`${winner.displayName} is the winner of the giveaway!`
);
}
async execute(interaction) {
let messageOption = await interaction.options.getString("targetmessage");
let emojiOption = await interaction.options.getString("entryemoji");

var message = await interaction.channel.messages.fetch(messageOption);

var reactedUsers = await message.reactions.cache.filter((reaction) => {
reaction.emoji.name == emojiOption;
}).users;

var winner = reactedUsers[Math.random(reactedUsers.count() - 1)];

await interaction.reply(
`${winner.displayName} is the winner of the giveaway!`
);
}
chewie
chewie8mo ago
you aren't returning a value in the filter function
Madder
MadderOP8mo ago
it's always the dumbest mistakes huh Sorry, from what I can tell the filter function doesn’t require a return value, just as the native JS array.filter doesn’t require one (docs say they’re near identical but that collection.filter returns a collection rather than an array).
chewie
chewie8mo ago
They require a return value :thonk: a boolean to be precise, to know what passes the filter and what doesnt https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#callbackfn
Madder
MadderOP8mo ago
Okay, my bad Okay, that worked. Now reactedUsers is a Map with size 0, even though the message being pulled has 2 💩 reactions on it.
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });
let messageOption = await interaction.options.getString("targetmessage");
let emojiOption = await interaction.options.getString("entryemoji");

let message = await interaction.channel.messages.fetch(messageOption);

let reactions = await message.reactions.cache.filter((reaction) => {
return reaction.emoji.name == emojiOption ? true : false;
});

let reactedUsers = await reactions.get(emojiOption).users.cache;

let winner = reactedUsers[Math.random(reactedUsers.count() - 1)];

await interaction.editReply(
`${winner.displayName} is the winner of the giveaway!`
);
}
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });
let messageOption = await interaction.options.getString("targetmessage");
let emojiOption = await interaction.options.getString("entryemoji");

let message = await interaction.channel.messages.fetch(messageOption);

let reactions = await message.reactions.cache.filter((reaction) => {
return reaction.emoji.name == emojiOption ? true : false;
});

let reactedUsers = await reactions.get(emojiOption).users.cache;

let winner = reactedUsers[Math.random(reactedUsers.count() - 1)];

await interaction.editReply(
`${winner.displayName} is the winner of the giveaway!`
);
}
Madder
MadderOP8mo ago
is this the problem?
No description
d.js docs
d.js docs8mo ago
:method: GuildMemberManager#fetch @14.15.2 Fetches member(s) from a guild.
// Fetch all members from a guild
guild.members.fetch()
.then(console.log)
.catch(console.error);
// Fetch all members from a guild
guild.members.fetch()
.then(console.log)
.catch(console.error);
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
chewie
chewie8mo ago
no you should not do that you can just fetch the reaction and that should contain the users, hopefully
Madder
MadderOP8mo ago
How would I fetch the reaction?
chewie
chewie8mo ago
add a .fetch() to it
No description
chewie
chewie8mo ago
I'm not 100% certain if that fetches the users though
Madder
MadderOP8mo ago
still a map with size 0 let reactedUsers = await reactions.get(emojiOption).fetch(); ahh okay let reactedUsers = await reactions.get(emojiOption).users.fetch(); empty map
Madder
MadderOP8mo ago
No description
No description
No description
Madder
MadderOP8mo ago
two reactions, one from myself and one from my friend the message id there is definitely correct sure one sec
Madder
MadderOP8mo ago
how would i do that? here's emojiOption
No description
Madder
MadderOP8mo ago
i've just never seen that format before, apologies one sec okay this is working keys and emoji came out to 💩 now winner is undefined but that's not djs, just js, i can get that fixed thank you all!

Did you find this page helpful?