2.1.1 • Published 5 years ago

d.js-mentions v2.1.1

Weekly downloads
2
License
UNLICENSED
Repository
github
Last release
5 years ago

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, or channel 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));
        }
    }
});
2.1.1

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago