Skip to content
Advertisement

(Discord.JS) How do I listen for a user mention for a specific user chosen by the author

So I am in the process of making a Discord.Js bot that includes a command that will let me provide information on certain users. For example: I want to add a command that will provide the PlayStation gamer tag of a mentioned user (lets say the specific users id is <@123>). The input message would look something like this :

“!psn @mention” then the bot would output his gamertag which I will manually log as–> message.channel.send(‘Here is <@1235467890> ‘s @psnname’);

I want to include the gamertag every member in my server so anyone can request it upon mentioning it with the command “psn”, I have gone through tons of trial and error with different code but i can not figure out how to specify the message.mention.members.first(); by a specific user id. Please help

module.exports = {

name: 'codtag',
execute(message, args){

    let member = message.mentions.members.first();

    if(!args.length){
        return message.channel.send({embed: {
            
            color: '#da1801',
            title: 'Activision Gamertag: Error',
            description: 'You need to tag a user dummy.'
    }})
}  
   
   if (member !== '<@772597378142306354>')return;
       else if (member === `772597378142306354`)return 
       {
    (args[0] === member)
        return message.channel.send({embed: {
            
            color: '#1243c6',
            title: 'Activision Gamertag',
            description: 'Here is <@772597378142306354> Activision: nn **WalterWhite#2396124**'
     
        }});

    }}

}

Advertisement

Answer

For anyone that finds this post with the same question, I figured it out. The following code works perfectly

I added: let guild = message.mentions.members.first();

I also included the condition for args[0] as: if (message.mentions.members.had('put users id here without the <@>')

module.exports = {

    name: 'cod',
     execute(message, args){


      let guild =  message.mentions.members.first();

        if(!args.length){
            return message.channel.send({embed: {
                
                color: '#da1801',
                title: 'Activision Gamertag: Error',
                description: 'You need to tag a valid user dummy.'
        }})
    }  
       
     if(message.mentions.members.has('772597378142306354')){
     
     (args[0] == guild)
             message.channel.send({embed: {
                
                color: '#1243c6',
                title: 'Activision Gamertag',
                description: 'Here is <@772597378142306354> Activision: nn **WalterWhite#2396124**',
                footer: {

                    text: 'Message @issmayo if your gamertag is not included.'
                }
         
            }});
   
        }
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement