2.1.1 • Published 5 years ago
d.js-mentions v2.1.1
Install
npm i d.js-mentions
About
Easily extract a member, role, or channel from a Discord mention using Discord.js.
Usage
const getMention = require('d.js-mentions');
var mention = getMention('not a mention'); // undefined
var member = getMention('<@189855563893571595>', someGuild).member; // GuildMember
var id = getMention('<@189855563893571595>').member; // '189855563893571595'
- If a valid mention and guild are provided, the response will be an object with a
member
,role
, orchannel
property as the mentioned object. - If the string provided is not a mention,
undefined
will be returned. - If the guild parameter is omitted, the returned object's property will be the ID in the mention.
Example
// reply with '👀' when someone mentions the bot
client.on('message', message => {
if (!message.guild || message.author.bot) return;
var mention = getMention(message.content, message.guild); // { member: GuildMember }
if (mention) {
var member = mention.member; // GuildMember
if (member && member.user.id === client.user.id) {
console.log('I was mentioned.');
message.channel.send(':eyes:')
.catch(err => console.error(err));
}
}
});