简体   繁体   中英

How can make a Mention Avatar command in discord.js bot?

can i make a mentioned avatar command with this code?

Here is my code :

const MessageEmbed = require('discord.js');

module.exports = {
name: "avatar",
aliases: ["AVATAR","av","profile","pfp"],
description: "Show your or other's Discord Avatar",
execute(message) { 
var avur = `${message.author.displayAvatarURL({ dynamic:true , format: 'gif', size: 256})}` ;
const Av = new Discord.MessageEmbed() 
        .setTitle(`${message.author.username}`)
        .setDescription(`**Avatar**'`)
        .setImage(avur) 
        .setColor('000000'); 
message.channel.send(Av)
   }
} 

Use:

const { MessageEmbed } = require('discord.js');

module.exports = {
name: "avatar",
aliases: ["AVATAR","av","profile","pfp"],
description: "Show your or other's Discord Avatar",
execute(message) { 
let user = message.author || message.mentions.users.first() || message.guild.members.cache.get(message.content.substring(5));
var avur = `${user.displayAvatarURL({ dynamic:true , format: 'gif', size: 256})}` ;
const Av = new Discord.MessageEmbed() 
        .setTitle(`${message.author.username}`)
        .setDescription(`**Avatar**'`)
        .setImage(avur) 
        .setColor('000000'); 
message.channel.send(Av)
   }
}

Here's a fix to your code, it works for me

const Discord = require('discord.js');
    module.exports = {
    name: 'avatar',
    aliases: ['AVATAR', 'av', 'profile', 'pfp'],
    description: "Show your or other's Discord Avatar",
    execute(message) { 
            let user = message.mentions.users.first() || message.author
            let avur = user.displayAvatarURL({ dynamic: true, size: 256, })
            let Av = new Discord.MessageEmbed()
        .setColor('000000')
        .setDescription('**Avatar**')
        .setTitle(`${user.tag}`)
        .setImage(avur)
        
        message.channel.send(Av);
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM