在一条等待消息后发送多条等待消息

Send several waiting messages after a waiting message

我正在寻求你的帮助。 我正在尝试发送一条等待回复的消息,然后当用户在时限内回答时,它会发送另一条消息,就像这条消息一样。 我不知道你是否明白我的意思。 如果您需要更多信息,请不要回答。

此致

我当前的代码:

const filter = m => m.author.id === message.author.id && m.author.id !== bot.user.id

// CHOISIR LE NOM

            message.reply("S'il vous plaît choisissez un nom pour le tournoi.").then(r => r.delete(10000));
            message.channel.awaitMessages(filter, {
              max: 1,
              time: 10000
            }).then(collected => { 
              if(collected.first().content === "stop" || collected.first().content === "cancel"){
                return message.reply("Création du tournoi annulé.")
              }
              let tournamentname = collected.first().content;
              db.collection("tournois").findOneAndUpdate({"tournamentInformations.status": "active"}, {
                $set: {
                  "tournamentInformations.tournamentName": tournamentname
                  }}, {upsert: true}, function(err,doc) { if (err) { throw err; } });
              message.channel.send(":white_check_mark: | Vous avez défini le nom du tournoi à "+tournamentname);
                }).catch(err => {
                  console.log(err)
                })

// CHOISIR L'ORGANISATEUR

            message.reply("S'il vous plaît choisissez le nom de l'organisateur.").then(r => r.delete(10000));
            message.channel.awaitMessages(filter, {
              max: 1,
              time: 10000
            }).then(collected => { 
              if(collected.first().content === "stop" || collected.first().content === "cancel"){
                return message.reply("Création du tournoi annulé.")
              }
              let organisateur = collected.first().content;
              db.collection("tournois").findOneAndUpdate({"tournamentInformations.status": "active"}, {
                $set: {
                  "tournamentInformations.organizedBy": organisateur
                  }}, {upsert: true}, function(err,doc) { if (err) { throw err; } });
              message.channel.send(":white_check_mark: | Vous avez défini l'organisateur à "+organisateur);
                }).catch(err => {
                  console.log(err)
                })

您似乎需要 .awaitMessages.then 排序 - 我强烈建议您在发帖前用谷歌搜索您的问题至少 30 分钟,并积极搜索 official Discord.js documentation 事先.

我可以提供一个简单的例子:

message.channel.send('First question').then(async (first) => {
            message.channel.awaitMessages(filter, { maxMatches: 1, time: 60000, errors: ['time']}).then(async (collected) => {
                await first.delete()
                await collected.first().delete()
            }).then(async () => {
                message.channel.send('Question 2').then(async (second) => {
                    message.channel.awaitMessages(filter, { maxMatches: 1, time: 60000, errors: ['time']}).then(async (collected) => {
                        await second.delete()
                        await collected.first().delete()
}).catch(collected => {
message.channel.send('Your answer timed out')
})

}).catch(collected => {
message.channel.send('Your answer timed out')
})

这样做(草率地,当我复制并粘贴此代码段并从我自己的代码对其进行编辑时,它可能缺少标记)是发送第一条消息 'First question' 并允许 60 秒的响应时间范围。如果有答案,它会删除问题提示和答案(您可以根据需要存储答案),然后它继续对第二个问题执行相同的操作,依此类推。如果 60 秒的时间范围到期,它将结束序列并告诉用户他们 运行 超时。

希望这对您有所帮助,如果有帮助,请将其标记为正确。

(P.S。如果你熟悉函数,所有这些都可以合二为一以压缩和简化你的代码,我只是提供了这样的例子以免你混淆)