简体   繁体   English

我如何获得集合的大小

[英]How do i get the size of the collection

I am using discord.js message collectors.我正在使用 discord.js 消息收集器。 How can I check if no message was sent and give the error that time is up?如何检查是否没有发送消息并给出时间已到的错误? Because as of now, there is no message sent if no messages were collected in the end event.因为到目前为止,如果在结束事件中没有收集到消息,则不会发送任何消息。

let filter = m => m.author.id === message.author.id
const collector = new MessageCollector(message.channel, filter, {max: 1, time: 1000 * 20})
collector.on('end', async m => { ...........

The MessageCollector class provides us with the parameter of the collected elements through the end event. MessageCollector class 通过end事件为我们提供了collected元素的参数。 We can use it to determine how many messages were collected by simply typing:我们可以使用它来确定收集了多少消息,只需键入:

collector.on('end', async m => console.log(m.size))
collector.on('end', async m => { if(m.size === 0){ // Do stuff here if no messages have been collected } else { // Do stuff here if at least 1 message has been collected } })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM