Home > Back-end >  awaitMessages doesn't works in Discord.js v13
awaitMessages doesn't works in Discord.js v13

Time:12-21

I recently updated my bot to v13, but all commands that use awaitMessages doesn't work anymore. Here is my code:

    if (hasPermission == true) {
      let firstEmbed = new Discord.MessageEmbed()
        .setTitle("Passaggio 1 (Grado di completamento: 0%)")
        .setColor("#b50000")
        .setDescription(
          "*Primo passaggio*, manda la **descrizione** del server con cui stai facendo partnership."
        )
        .setFooter("Tempo: 5 minuti");
        message.channel.send({embeds: [firstEmbed]}).then(() => {
        message.channel.awaitMessages((m) => m.author.id == message.author.id, {
            max: 1,
            time: 300000,
            errors: ['time']
          })
          .then((description) => {
            console.log("test 3")
            if (description.first().content.length > 1999) {
              return message.channel.send(
                "Errore! La descrizione è troppo lunga!"
              );
            }
            let descriptionToClean = description.first().content;
            let cleanDesc = cleanDescription(descriptionToClean);
            let secondEmbed = new Discord.MessageEmbed()
              .setTitle("Passaggio 2 (Grado di completamento: 33%)")
              .setColor("#d4750f")
              .setDescription(
                "*Secondo passaggio*, manda qui sotto l'ID del **gestore dell'altro server**, con cui stai facendo partner.\nTieni presente che il gestore deve essere in tutti i server della catena di cui fai parte.\nSe non vuoi mandare l'ID o non funziona il bot, scrivi `skip`."
              )
              .setFooter("Tempo: 5 minuti");
              message.channel.send({embeds: [secondEmbed]}).then(() => {
              message.channel
                .awaitMessages((m) => m.author.id == message.author.id, {
                  max: 1,
                  time: 300000,
                })
                .then((partnerManager) => {
                  let gestore;
                  let skip = false;
                  if(partnerManager.first().content.toLowerCase() == "skip") skip = true;
                  if(partnerManager.first().content) gestore = partnerManager.first().content;
                  let isIn = CheckIfManagerIsInServer(
                    client,
                    message.guild.id,
                    gestore
                  );

(note that this isn't the complete code, and I'm sure that not run only after the first awaitMessages) I think that the problem is this: awaitMessages doesn't collect any data. awaitMessages example

After message.channel.awaitMessages(), the code doesn't run.

CodePudding user response:

awaitMessages doesn't take multiple parameters.

Exerpt from the API docs

.awaitMessages([options])

// Await !vote messages
const filter = m => m.content.startsWith('!vote');
// Errors: ['time'] treats ending because of the time limit as an error
channel.awaitMessages({ filter, max: 4, time: 60_000, errors: ['time'] })
  .then(collected => console.log(collected.size))
  .catch(collected => console.log(`After a minute, only ${collected.size} out of 4 voted.`));

What you have as your first parameter should be the filter property of the AwaitMessagesOptions object

message.channel.awaitMessages({
  filter: (m) => m.author.id === message.author.id,
  max: 1,
  time: 300000,
  errors: ['time']
})
.then(...);
  • Related