javascript - 在 discord.js 中的时间限制之前获取收集的消息
问题描述
有没有办法在时间限制到期之前接收来自 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
才会发出事件。似乎它实际上并没有在收到消息时收集消息,而是在计时器用完时收集消息。这是否是故意的,我不确定。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);
});
推荐阅读
- angular - 如何重定向到Angular Universal中的动态外部URL?
- react-native - 世博相机没有显示相机看到的东西
- kotlin - 使用 randomUUID 时的 UUID 冲突
- influxdb - InfluxDB 1.7.2 - 随着时间的推移 Top X
- html - 仅在与主体形状接触时产生粘性效果
- ios - TableView根据单元格宽度水平滚动
- javascript - 在哪里存储访问令牌以供前端使用
- javascript - 为什么我的猫鼬验证回调返回;TypeError:响应不是函数
- json - JSON stringify 不产生预期的 json
- scikit-learn - 如何为 RandomSearchCV 定义具有两个隐藏层的 MLPR