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

133
Visualizações
How to use awaitMessages in Discord.JS v13

So, I want to wait for a message from user used specific command. I know that the filter is probably wrong, but I have no idea now how can I approach this.

I tried something like this:

const msg_filter = m => m.author.id === message.author.id;
message.channel.awaitMessages(msg_filter, {
    max: 1
});

But now, how can I get this working? Because I googled for several hours and couldn't find a way to solve this issue. I just want to fetch a message from same user as used the command (And I was only able to fetch message from bot, nothing more).

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

0

Here's a link to the documentation on TextChannel#awaitMessages

But in a nutshell, awaitMessages returns a promise that you have to resolve, like this:

const msg_filter = (m) => m.author.id === message.author.id;
const collected = await message.channel.awaitMessages({ filter: msg_filter, max: 1 });

// Or without async/await
const msg_filter = (m) => m.author.id === message.author.id;
message.channel.awaitMessages({ filter: msg_filter, max: 1 })
  .then((collected) => {
    // ...
  });

and collected will be a Collection of messages. Since you're only collecting 1 message, you can use collected.first() to get the first (and only) message in the collection, and then from there you can get it's .content, or .reply() to it, or do whatever else you want to do with the message.

about 4 years ago · Juan Pablo Isaza Relatório

0

Take a look at the official discordjs guide for this.

Example:

// `m` is a message object that will be passed through the filter function
const filter = m => m.content.includes('discord');
const collector = interaction.channel.createMessageCollector({ filter, time: 15000 });

collector.on('collect', m => {
    console.log(`Collected ${m.content}`);
});

collector.on('end', collected => {
    console.log(`Collected ${collected.size} items`);
});
about 4 years ago · Juan Pablo Isaza Relatório

0

Your format isn't wrong you just need to change the position of filter!

const msg_filter = m => m.author.id === message.author.id;
message.channel.awaitMessages({
    filter: msg_filter,
    max: 1
});

and make sure you put 'DIRECT_MESSAGES' on intents function

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