有没有办法在期限到期之前从discord.js收集器接收消息?
我尝试使用collector.oncollection,但在我设置的时间限制后触发。
这是我目前拥有的:
this.collected = false
this.collector = new Discord.MessageCollector(msg.channel, m => m.author.bot === false,{time: 10000});
this.collector.on('collect', message =>{
if(!this.collected){
this.collected = true
console.log(message)
msg.channel.send(message.content)
this.collector.stop()
//Insert the same thing here(Copy+Paste the same code here)
}
});
(这是为了全局性,因为它必须是递归的)
我希望收集器在收到第一条消息时就发出一个事件,但是对于当前代码,它仅在时间限制之后执行。
答案 0 :(得分:0)
经过一些测试,看来collect
事件仅在达到设置的time
选项后 发出。看起来好像实际上不是在接收消息时收集消息,而是在计时器用尽时收集消息。我不确定这是否有意。
由于只需要一定数量的消息,因此可以设置收集器的maxMatches
选项。然后,如果在达到time
限制之前收集了该数量的邮件,则收集器将发出collect
事件并停止。
this.collector = new Discord.MessageCollector(msg.channel, m => !m.author.bot, { maxMatches: 1, time: 10000 });
this.collector.on('collect', message => {
msg.channel.send(message.content)
.catch(console.error);
});