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

128
Views
Discordjs - lastMessageId siempre evento nulo después de buscar

Introducción :

Soy bastante nuevo en la creación de discord BOT y actualmente estoy tratando de hacer como un bot de boletos. Para hacer eso, necesito verificar si el usuario que agrega la reacción puede hacerlo o no.

Código:

Ya verifiqué esto (con éxito) cuando el usuario está usando un comando gracias a esto (isAllow es una función personalizada que funciona cuando se pasa un objeto miembro en parámetros):

if (Common.isAllow(message.member)) { /* code ... */ }

Pero también quiero verificar los roles del usuario que está reaccionando a un mensaje, para crear un nuevo canal si el usuario puede hacerlo.

El problema es que cuando obtengo el objeto de usuario, lastMessageId es nulo, por lo que no puedo obtener el objeto miembro y verificar sus funciones.

El código que está comprobando la reacción es este:

 client.on("messageReactionAdd", async (reaction, user) => { // When a reaction is received, check if the structure is partial if (reaction.partial) { // If the message this reaction belongs to was removed, the fetching might result in an API error which should be handled try { await reaction.fetch(); } catch (error) { console.error('Something went wrong when fetching the message: ', error); // Return as `reaction.message.author` may be undefined/null return; } } switch (reaction.message.channel.id) { // Check if the message has been sent into the lawyer contact channel case Config.CHANNELS.LAWYER_CONTACT: case Config.CHANNELS.CONFIG: checkForLawyerChannelReaction(reaction, user); break; default: break; } });

Si la reacción se ha realizado en el canal bueno (LAWYER_CONTACT) o en el canal de configuración (CONFIG), llamará a esta función, que es la que intenta verificar el permiso:

 function checkForLawyerChannelReaction(reaction, user) { console.log('checkForLawyerChanelReaction'); console.log(user); if (Common.isAllow( /* member object */ ) { /* code ... */ }

La respuesta que obtengo para console.log (usuario) es: Resultado

Ya intenté obtener datos de usuario como este, y no cambia nada: console.log(await client.users.fetch('123456789123456789')); (La identificación ha sido cambiada, por supuesto)

Tenga en cuenta que el BOT se unió (nuevamente) ayer con permisos de administrador, y el usuario envió un mensaje desde ayer.

¿Alguien tiene una solución para esto o información que quizás no tenga todavía?

Gracias por tu tiempo.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede obtener el objeto GuildMember pasando el user como argumento al método Guild.member(user) .

 const guildMember = reaction.message.guild.member(user);
over 4 years ago · Santiago Trujillo 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!