Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda