I currently need to ping the person first then it will cache into the bot. After that, I would then be able to use their ID.
How do I make it so I can use their ID straight away?
This is my avatar command. How would I go to improve and add that command?
module.exports = {
config,
run: async (client, message, args) => {
let embed = new Discord.MessageEmbed();
let mention = message.mentions.members.first()
if(!mention && !isNaN(args[0]) && args[0]) try {mention = await client.users.fetch(args[0])} catch (err) {}
if(!mention && args[0] && isNaN(args[0])) try {mention = await message.guild.members.fetch({query: args[0], limit: 1})} catch (err) {}
if(!mention) mention = message.author
if(mention.roles) mention = mention.user
let user = message.mentions.users.first()
|| message.guild.members.cache.get(args[0])?.user
|| message.author;
embed.setTitle('Avatar!');
embed.setAuthor(message.author.tag, message.author.displayAvatarURL());
embed.setColor(client.config.colors.info);
embed.setImage(user.displayAvatarURL({dynamic: true}));
return message.reply({embeds: [embed] });
}
}