Miskakao
Miskakao

Reputation: 99

discord.js - How to get specific collected message

I'm trying to get specific collected message, e.g. 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}`)
    })
})

Upvotes: 1

Views: 672

Answers (1)

Zsolt Meszaros
Zsolt Meszaros

Reputation: 23189

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)

Upvotes: 2

Related Questions