Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
V12 Discord.js retrieve user.id from a message reactions

i'm struggling to retrieve in V12 of discord.js the user.id and user.name for a message that they react too. The idea is a message is pinned and the user selects between 1-7 each day and it adds a point to their total. It will subtract from their total as well, if they deselect any of the reactions. But I haven't written that out yet. Currently it fails with TypeError: Cannot read property 'guild' of undefined on const Character when trying to get the user.id

config.json

{
"prefix":"!",
"channel": "xxx",
"channelID": "xxx",
}

SQLite

client.getdayCount = DB.prepare("SELECT dayCount from Table WHERE id = ?;");
client.setdayCount = DB.prepare("INSERT OR REPLACE INTO Table (id, dayCount, guild) VALUES (@id, @dayCount @guild);");

Main Code

client.on('messageReactionAdd', addRole);
client.on('messageReactionRemove', removeRole);

async function addRole(message, reaction, user) {

if (message.partial) {
   try {
       await message.fetch();
   } catch (err) {
  console.error('Error fetching message', err);
  return;
   }
}


client.channels.cache.get(config.channelID).messages.fetch({
limit: 1
}).then(messages => {
const lastMessage = messages.first()
const character = reaction.message.guild.member(user.id);
//Filter the reaction
const addition = +1;
if (lastMessage.reactions.cache.emojis === "1️⃣" || "2️⃣" || "3️⃣" || "4️⃣" || "5️⃣" || "6️⃣" || "7️⃣") {
  // Define the emoji user add
   //const character = lastMessage.guild.member(user.id);
  //reaction.message.guild.member(user.id);
  if (character) //if author has sent before
  {
      character.setdayCount += addition;
      client.setdayCount.run(character);
      return;
    
  } else //else add new author to collection
  {
    character = {
      id: user.id,
      setdayCount: addition,
      guild: reaction.guild.id,
    }

  }
} else {

};
}).catch(err => {
console.error(err)
})
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are using incorrect parameters for your function, in discord js v12 the messageReactionAdd only has two parameters, messageReaction and user. Therefore the parameter that you called reaction is actually a User object which doesn't have a property named message and causes your error.

Additionally

if (lastMessage.reactions.cache.emojis === "1️⃣" || "2️⃣" || "3️⃣" || "4️⃣" || "5️⃣" || "6️⃣" || "7️⃣") {

will always be true, I think what you intend to do is

if (["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣"].includes(lastMessage.reactions.cache.emojis)) {
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!