【发布时间】:2019-11-02 06:30:31
【问题描述】:
有没有办法在时间限制到期之前接收来自 discord.js 收集器的消息?
我尝试使用collector.on collect,但它在我设置的时间限制后触发。
这是我目前拥有的:
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 事件,因此您不必等待超时来获取收集的消息。如果删除
if (!this.collected)condition 会发生什么? -
哦,对不起,我忘了补充,我只需要收集一条消息,反正它遍历所有消息,我只需要收集一条消息。
-
collector.stop() 正如它所说的,应该停止收集器;所以你的情况对我来说似乎有点多余。否则,您的代码对我来说似乎很好,我不明白为什么它没有按预期工作。顺便说一句,您的评论
\\Insert the same thing here是什么意思?您的问题中是否还有更多代码未包含在内? -
是的,它必须是递归的
标签: javascript node.js discord.js