【问题标题】:bot doesn't collect the messages ASAP机器人不会尽快收集消息
【发布时间】:2021-04-22 20:06:40
【问题描述】:

我正在使用 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)    
   })
})

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    你写的是max: questions.Lenght而不是max: questions.length,而Lth是小写的

    【讨论】:

      猜你喜欢
      • 2020-08-12
      • 1970-01-01
      • 2021-10-27
      • 2022-01-21
      • 2021-03-31
      • 2021-12-11
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多