Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda