Closed allenhe77 closed 2 years ago
bot.on('message', (msg) => {
console.dir(msg)
getUserMention(msg)
})
const getUserMention = (msg) => {
if (msg.entities && msg.entities.length > 0) {
// Users with username @
let mentions = msg.entities.filter(e => e.type === 'mention')
// Users without username @
let text_mentions = msg.entities.filter(e => e.type === 'text_mention')
if (mentions) {
mentions.forEach(mention => {
let mentionUsername = msg.text.substring(mention.offset, mention.offset + mention.length)
// in the mentions of the users with alias the "user" object is not present.
// So the better way is use a userbot for resolve the alias or save in the database the alias and the user id
// when the users talk with the bot on in the chart
console.dir(mentionUsername)
})
}
if(text_mentions) {
text_mentions.forEach(mention => {
// User data
console.dir(text_mentions.user)
})
}
}
}
I have a bot that parses the message when a user '@' another user, I was wondering if the library has a feature to get the firstName of the quoted user.