collector.on('collect', message => {
if (message.content === 'bla bla bla') {
message.channel.send(`bla bla bla`);
collector.stop();
}
})
collector.on('end', data => {
if (!data.first()) {
console.log('TimeOut');
}
})我想在它到达collector.on('end' )事件之前做一些检查。我想检查事件是因为超时还是因为.stop()而结束。我该怎么做呢?
发布于 2019-03-12 23:33:41
根据文档,您可以在collector.stop()中传递一个可选参数作为原因。collector.on('end', ...)还包括此可选参数。因此,只需在.stop()方法中传递一个字符串,就应该能够执行所需的操作。
下面是一些示例代码,试一下,让我知道它是如何进行的。
collector.on('collect', message => {
if (message.content === 'bla bla bla') {
message.channel.send('bla bla bla');
collector.stop('Collector stopped manually');
}
});
collector.on('end', (collected, reason) => {
if (reason && reason === 'Collector stopped manually') {
console.log('Collector has been stopped manually');
} else {
console.log('Collector has NOT been stopped manually');
}
});https://stackoverflow.com/questions/55117396
复制相似问题