Reputation: 45
I'm trying to count the amount of times a user has been mentioned in a channel. The code I have is:
message.channel.messages.fetch()
.then(messages => console.log(`${messages.filter(m => m.mentions.users[1] === 'msg.author').size} messages`))
.catch(console.error);
When I ran this in a channel I had 27 mentions in that channel's history. This returned 0 messages
.
How do I accomplish this?
Upvotes: 0
Views: 227
Reputation:
error is with your filter,
m.mentions.users
is a collection mapped by the users id, when you do [1] it checks for a user with the id of 1 and then checks it to the string msg.author
message.channel.messages.fetch()
.then(messages => {
//.has() checks if the collection includes the key
const size = messages.filter(m => m.mentions.users.has(message.author.id)).size;
console.log(size, "messages");
});
.catch(console.error);
Upvotes: 1