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

272
Visualizações
Change message with reactions Discord.js

Im a bit new creating Discord bots, my plan with this is to have like a book with the help command that if you press the arrow it changes to the next page, and if you press another arrow it changes to the previus page, I'll simpifly my code to make it more easier to understand.

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
        }
    })
}

I know this isnt going to work but i hope you understand the major idea, how can i do this so it actually works?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you want to listen for reactions to old messages you need to fetch the messageId, etc. This is simple to understand. Here is a Guide.

If you only want it to send a message, react to it, and listen to the next reaction it's easier. There is also a Guide for it.

In your case with the book, I would use the second method and then loop it. So if someone presses the button it starts the function from the beginning.

This is only an example I never tested it and can't say if it works, It's only made to show you what I meant:

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=>{});
            });
    });
};

I hope that it was a bit helpful.

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