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

268
Views
Cambiar mensaje con reacciones Discord.js

Soy un poco nuevo creando bots de Discord, mi plan con esto es tener como un libro con el comando de ayuda que si presionas la flecha cambia a la página siguiente, y si presionas otra flecha cambia a la página anterior, yo Simplificaré mi código para que sea más fácil de entender.

 async execute(message, client){ var msg1 = await message.channel.send('how are') msg1.react('▶') //send the message client.on('messageReactionAdd', async (reaction, user) =>{ //wait for the reaction if(user.bot) return if (message.reaction.id === msg1.id){ message.channel.messages.fetch(msg1.id).then(msg => msg.delete()) var msg2 = await message.channel.send('you?') msg2.react('◀') //delete the previus message, send the second and react to it } else if (message.reaction.id === msg2.id){ message.channel.messages.fetch(msg2.id).then(msg => msg.delete()) var msg1 = await message.channel.send('how are') msg1.react('▶') //delete the second message, send the first and react } }) }

Sé que esto no va a funcionar, pero espero que entiendas la idea principal, ¿cómo puedo hacer esto para que realmente funcione?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si desea escuchar las reacciones a los mensajes antiguos, debe obtener el ID del mensaje, etc. Esto es fácil de entender. Aquí hay una guía .

Si solo desea que envíe un mensaje, reaccione y escuche la siguiente reacción, es más fácil. También hay una guía para ello.

En su caso con el libro, usaría el segundo método y luego lo repetiría. Entonces, si alguien presiona el botón, comienza la función desde el principio.

Este es solo un ejemplo, nunca lo probé y no puedo decir si funciona, solo está hecho para mostrarle lo que quise decir:

 const reactionName1 = '▶'; const reactionName2 = '◀'; const text1= 'How are'; const text2 = 'you?'; module.exports = { async execute(message, client) { if(message.author.user.bot) return; message.channel.send('Hello!').then(msg => { nextMessage(msg, message.author, reactionName1, text1) }); }, } function nextMessage(message, author, reactionName, text) { message.edit(text).then(() => { message.react(reactionName); const filter = (reaction, user) => { return [reactionName].includes(reaction.emoji.name) && user.id === author.id; }; message.awaitReactions({ filter, max: 1, time: 60000, errors: ['time'] }) .then(collected => { const reaction = collected.first(); message.reactions.removeAll(); if(reaction.emoji.name === reactionName1) return nextMessage(message, author, reactionName2, text2); if(reaction.emoji.name === reactionName2) return nextMessage(message, author, reactionName1, text1); }) .catch(collected => { message.reactions.removeAll(); return message.edit('You had to press the reaction').then(() => message.delete({ timeout: 4000 })).catch(o_O=>{}); }); }); };

Espero que haya sido un poco útil.

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!