简体   繁体   中英

discord.js - How to get specific collected message

I'm trying to get specific collected message, eg third collected message. The forEach works perfect, but I need just one specific, like I said previously.

collector.on('end', collected => {
    console.log(`Collected ${collected.size} messages`)

    message.channel.send(`${collected}`)

    collected.forEach(value => {
      message.channel.send(`${value}`)
    })
})

collected is a Collection , not an array. You can find the documentation here .

You could use the .at(index) method that returns the item at a given index. So in order to get the third item, you could use the following:

let thirdCollectedMessage = collected.at(2)

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