Console.log(user) returns undefined

Well, this problem has been bothering me for some time now, and I’ve kept putting it off, but now it’s time to get rid of this error.

I am trying to add some users to an array, in a way that makes it easy to just pull them forth and used them as mentions. Right now I have a reaction collector, and I’'m trying to pull out the users from there with two exceptions; the user and the bot. The reason the user isn’t going to matter, is because they should already be a part of the array.

For some context, I’m making a racing game, where you join by reacting and then after 60 seconds the game start and you hope to win. I’ve made a collector using the example on the Collectors | Discord.js Guide-site, but whenever I try to get the user who sent the message, and only the one who sent the message just then (Because the bot appears for every time I log reaction.users, even though it only reacts once). I’ve tried logging user, reaction.user, users and reaction.users.

And also, the collected.size gave me -1

Edit: Forgot to add some referencing code, but here you go

players.push(message.author)
message.channel.send(track).then(sentEmbed => {
sentEmbed.react(car)
const filter = (reaction, user) => {
return reaction.emoji.name === ‘:racing_car:’;
};
const collector = sentEmbed.createReactionCollector(filter, { time: 15000 });
collector.on(‘collect’, (reaction => {
console.log(user)
console.log(“\n\n\n”)
}));
collector.on(‘end’, collected => {
let track = new Discord.RichEmbed()
.setTitle(“Owned by the Monimuffin Server”)
.setAuthor(“Formuffina 1”, “https://cdn.glitch.com/bdd2abbd-8294-4499-912d-00f9d20e3a1e%2Fa_cf72f7bf4419755aefe87ac271108514.gif?v=1571297404455”)
.setColor(0xffffff)
.setDescription(“It’s a beautiful day outside. Birds are singing, flowers are blooming… \n We are here on the Monimuffin racing track, Sponsored by the Monimuffin server!”)
.setImage(‘https://cdn.glitch.com/bdd2abbd-8294-4499-912d-00f9d20e3a1e%2FSS-Tracks-Concession.png?v=1571439489377’)
.addBlankField()
.addField(“Instructions”, “Attend the race by reacting with” + car + “\nDepending on your car, you have a varying chance of success\nThis is a very dangerous race, and many will not finish\n Only those who manage to finish the race will be rewarded”)
.setFooter(“Current players: 1”);
sentEmbed.edit(track)
})}

Anyways, all help would be greatly appreciated. So as always, thanks in advance, and have a marvelous day!

The way I do reaction roles on my bot for my discord server - I have channel the message is being sent to, completely cleared when the bot starts, then it sends the message, react for this blah blah, then I have a messageReactionAdd event, which the start of it, looks like this:

const { RichEmbed } = require('discord.js');

exports.run = async(client, messageReaction, user) => {
	const { message, emoji } = messageReaction;
	if (user.bot) return; // Dont include bots
	if (user.id === '480421483575902208' || // The bots id - So it does not include the bot
    message.channel.id !== '612438538000138240' || // Make sure its only in the channel the message was sent at the start
    emoji.name !== '📥') return; // Make sure the emoji is correct

Hope that helps at all!

1 Like

It won’t let me pass the exports.run. I’ve used console log on both sides, only the first one returns, meaning the code stops working right there. If you could explain to me a little bit how that part works, I may be able to find a workaround though, so thanks

Nvm, found a solution.

For anyone who also wonders about this, here’s my solution:

client.on(‘messageReactionAdd’, (reaction, user) => {
if(reaction.emoji.name === candy && reaction.users.last() === user1) {//user1 is a variable I used earlier to find the mention, and candy is another variable
[Your code here]
} else if(reaction.emoji.name === trick && reaction.users.last() === user1 && message.author.lastMessage) {//trick is also another variable
[Your code here]
}});

This checks for two different reactions, and if the user reaction is the specified user. If there is anything just comment and I will answer as soon as I can.

1 Like