G
G
getaxe2022-02-01 11:43:30
Node.js
getaxe, 2022-02-01 11:43:30

How to catch the user's next message?

I need to catch the user's next message, and take content from it.
For example:

message.reply('укажите число')
ephemeral: true
????

//ответ бот ожидает в течении 10 секунд, после чего 
message.reply('Прошло 10 секунд, попробуйте еще')
ephemeral: true

ps Alexander, I hope you don't mind that I choose you as an expert. It's just that you helped 2/2 and answered very clearly :)

update: I
tried to do it through timeout, but if there is a message, kill the timeout through return;
But for some reason it doesn't work =/
bot.on('messageCreate', (message) => {
  if(message.author.id !== "337262564289282051") {
    return;
  }
  if(message.content == "222") {	
    bot.on('messageCreate', (message) => {
      if(message.author.id !== "337262564289282051") {
        return;
      }
      //if канал пользователь
      console.log('123')
      return;
    })
    setTimeout(() => {
      console.log("321");
      return;
    }, 10000);
    return;
  };
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2022-02-01
@getaxe

if (message.content === ...) {
    const collector = message.channel.createMessageCollector({
        time: 10000
    });

    let userMessage = [];

    collector.on('collect', m => {
        if (m.author.id === message.author.id) {
            userMessage.push(m.content);
            collector.stop();
        }
    })

    collector.on('end', collected => {
        if (userMessage.length === 0) return message.reply(`Прошло 10 секунд, попробуйте ещё.`)

        // userMessage[0] - контент первого сообщения, отправленного пользователем
    });
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question