有没有办法在时间限制到期之前接收来自discord.js收集器的消息?
我尝试使用collector.on收集,但它在我设置的时间限制后触发。
这是我目前拥有的:
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)
}
});
(一切上的 this 都是为了全局性,因为它必须是递归的)
我希望收集器在收到第一条消息时发出一个事件,但使用当前代码,它只会在时间限制之后才执行此操作。
经过一些测试,似乎collect https://discord.js.org/#/docs/main/stable/class/MessageCollector?scrollTo=e-collect事件仅被发出after集合time https://discord.js.org/#/docs/main/stable/typedef/CollectorOptions已达到选项。似乎它实际上并不是在收到消息时收集消息,而是在计时器耗尽时收集消息。我不确定这是有意还是无意。
由于您只需要一定数量的消息,因此您可以设置maxMatches https://discord.js.org/#/docs/main/stable/typedef/MessageCollectorOptions您的收藏家的选择。那么,如果在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);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)