From 13b98b5f5955b3cecd7594454536419ea263e7dd Mon Sep 17 00:00:00 2001 From: Emily J Date: Sun, 11 Oct 2020 12:05:55 +1100 Subject: [PATCH] added avatar command (need to do embed colour) --- bot/commands/Utility/avatar.js | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 bot/commands/Utility/avatar.js diff --git a/bot/commands/Utility/avatar.js b/bot/commands/Utility/avatar.js new file mode 100644 index 0000000..f992fd7 --- /dev/null +++ b/bot/commands/Utility/avatar.js @@ -0,0 +1,55 @@ +const Discord = require('discord.js'); +const Command = require("../../base/Command.js"); + +class Avatar extends Command { + constructor (client) { + super(client, { + description: "View a full-sized image of a person's profile picture.", + usage: "avatar ", + examples: "`avatar` - Gets your avatar.\n`avatar emily` - Gets the avatar of the user 'emily' ", + aliases: ["pfp"], + botPerms: ["EMBED_LINKS"] + }); + } + + async run (message, args, data) { // eslint-disable-line no-unused-vars + if(!args[0]) { + const embed = this.createEmbed(message.author); + return message.channel.send(embed); + }; + + let user = message.mentions.users.first(); + + if (!user && message.guild) { + user = this.client.functions.searchForMembers(message.guild, args[0]); + if (user.length > 1) { + return message.channel.send( + 'Found multiple users, please be more specific or @mention the user instead.' + ); + }; + + if (user.length < 1) { + return message.channel.send( + 'Specified user couldn\'t be found, check for typing errors.' + ); + }; + }; + + user = user[0].user; + + const embed = this.createEmbed(user); + return message.channel.send(embed); + }; + + createEmbed (user) { + const URL = user.avatarURL({format: "png", dynamic: true, size: 2048}) + const embed = new Discord.MessageEmbed() + .setTitle(user.tag) + .setDescription(`**[Avatar URL](${URL})**`) + .setImage(URL); + + return embed; + }; +}; + +module.exports = Avatar;