机器人不会尽快收集消息

时间:2021-04-21 12:23:21

标签: discord.js

我正在使用 Discord.js 制作应用程序。一切正常,但机器人不会在回答所有问题后立即收集消息。
它会在收集器耗尽时间时执行。

在回答完所有问题后如何触发 collector.on('end' ...)

 const questions =[
        'First Name:',
        'Last Name:',
        'How old are you:',
        'Your email:',
        'What is your time zone:',
        'Where are you from:',
        'What languages are you speaking:',
        'Have your ever been punished on our server:',
        'On which server your most active on:',
        'Have you ever been in a staff team:',
        'Tell us about your self:'
]

let counter = 0
    
const filter = m => m.author.id === message.author.id
    
const collector = message.author.dmChannel.createMessageCollector(filter, {
   max: questions.Lenght,
   time: 60000                     
});
       
message.author.send(questions[counter++]);

console.log(`1st question has been sent to ${message.author.tag}`);

collector.on('collect', (m) => {
   if(counter < questions.length) {
      console.log(`sending more questions to ${message.author.tag} until answer them all`);
      message.author.send(questions[counter++])   
   }
})

collector.on('end', (collected) => {
   console.log(`collected ${collected.size} messages`);

   message.author.send(`Your application has been successfully sent`);
   let counter = 0
   collected.forEach((value) => {
      console.log(questions[counter++], value.content)    
   })
})

1 个答案:

答案 0 :(得分:1)

你用较低的 max: questions.Lenghtmax: questions.length 写了 L 而不是 th