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

388
Visualizações
why is message.channel.awaitMessages() not working? | Discord.js V13

I'm trying to collect a message after a certain message a user has sent in a specific channel. So the user would send say hello world then await messages would wait for a response from a specific user and grab that message's ID. However, it doesn't work.

Here is my code:

let filter = message => {
    return message.author.id == 'ID OF USER';
}

if(message.channel.id == 'channel id of sent message') {
            console.log('here');
            if(message.content.valueOf("hello world")) {
                console.log('here');
                message.channel.awaitMessages(bumpFilter, { max: 1, time: 5000, errors: ['time']})
                .then(c => {
                    console.log('here');
                    console.log(c);
                });
            }
        }

In the console, here is logged 2 times. However, the 3rd time is not logged, even after the 5 seconds has passed from this message. The console logs nothing, not even an error, which got me to speculate that maybe it's an discord intents issue, but i don't think that was it either. So i don't understand what's the issue and why I won't get any results. Also, if i assigned message.channel.awaitMessages(...) to a var then logged the var it would output Promise { <pending> } and I read that a .then statement has to be added to avoid that. And now that it is added, it still does not output anything.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

First, if (message.content.valueOf("hello world")) will always return true as the valueOf method returns the primitive value of the specified object. Even if message.content is not "hello world", it's still truthy. You should check if the value of message.content itself is equal to "hello world".

Second, you declare a filter variable but you use bumpFilter in your awaitMessages

And third, in discord.js v13, awaitMessages accepts a single parameter, an options object. (In v12 the first parameter was a filter and the second one is the options).

let filter = (message) => {
  return message.author.id === 'ID OF USER';
};

if (message.channel.id === 'channel id of sent message') {
  console.log('channel matches');

  if (message.content === 'hello world') {
    console.log('message is hello world');

    message.channel
      .awaitMessages({ filter, max: 1, time: 5000, errors: ['time'] })
      .then((c) => {
        console.log('New message collected');
        console.log(c);
      })
      .catch((c) =>
        console.log(`After five seconds, ${c.size} messages are collected.`),
      );
  }
}
about 4 years ago · Santiago Trujillo 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