'Message Collector first Message

I'm using thecreateMessageCollector. It is collecting messages, but the problem is, that it is not getting the first message sent in the channel.

const filter = m => m.content.toLowerCase() === message.content.toLowerCase();
    const collector = message.channel.createMessageCollector(filter, { max: 1, time: 10000 })

    collector.on('collect', async collector => {
        console.log(collector.content)
    })

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

Need help in getting the first message sent in the channel.



Solution 1:[1]

I'm going to assume that you want the message from the same channel, so I changed your filter a bit, but the filter needs to be passed into the collector like below:

const filter = m => m.channel.id === message.channel.id
const collector = message.channel.createMessageCollector({
    filter,
    max: 1,
    time: 10000,
})

Solution 2:[2]

It's as easy as collected.first().

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gh0st
Solution 2 0xLogN