Martin Lukavec
Martin Lukavec

Reputation: 33

Get first message on channel

How to get first message on channel? I have really no idea how to do this and i didnt found anything on internet. I need it for getting first mention on channel, so if there is some easier way (than getting first message), you can also post it.

Upvotes: 1

Views: 4558

Answers (1)

SomeCoder
SomeCoder

Reputation: 293

You can get all messages with fetchMessages() and then loop over and check for mentions:

message.channel.fetchMessages().then(messages => {
    messages.forEach((item, index)=>{
        // do something with 
        // item.mentions
        // documentation: https://discord.js.org/#/docs/main/stable/class/MessageMentions
     });
}).catch(err => {
    console.log('Error while getting mentions: ');
    console.log(err);
});

Upvotes: 1

Related Questions