简体   繁体   中英

How do i get the size of the collection

I am using discord.js message collectors. 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. 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 } })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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