From 2f9218ac47114dd7c13911d3bbbdb2ab37ca96ff Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 29 Apr 2022 20:05:53 +0300 Subject: [PATCH] avatar command --- .../components/commands/utility/Avatar.js | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/structure/components/commands/utility/Avatar.js diff --git a/src/structure/components/commands/utility/Avatar.js b/src/structure/components/commands/utility/Avatar.js new file mode 100644 index 0000000..9d3c49f --- /dev/null +++ b/src/structure/components/commands/utility/Avatar.js @@ -0,0 +1,62 @@ +const { SlashCommand } = require("../../../interfaces"); + +class AvatarCommand extends SlashCommand { + + constructor(client) { + super(client, { + name: 'avatar', + description: 'Retrieve user avatar', + module: 'utility', + options: [{ + name: 'size', + description: 'The width/height value', + // type: 'INTEGER', + choices: [16, 32, 64, 128, 256, 512, 1024, 2048].map((i) => { + return { name: `${i}`, value: `${i}` }; + }) + }, { + name: 'format', + description: 'Image format', + // type: 'STRING' + choices: ['webp', 'png', 'jpeg', 'jpg', 'gif'].map((i) => { + return { name: i, value: i }; + }) + }, { + name: 'user', + description: 'Use this for the user\'s global avatar', + type: 'USER' + }, { + name: 'member', + description: 'Use this for the user\'s server avatar', + type: 'MEMBER' + }] + }); + } + + async execute(invoker, { format, size, user, member }) { + + const target = member?.value || user?.value || invoker.member || invoker.author; + format = format?.value || 'webp'; + size = parseInt(size?.value || 256); + + let avatar = null; + try { + avatar = target.displayAvatarURL({ format, size, dynamic: true }); + } catch (err) { + return { emoji: 'failure', index: 'COMMAND_AVATAR_FORMATERROR' }; + } + + return { + embed: { + title: target.user?.tag || target.tag, + description: `[**Link**](${avatar})`, + image: { url: avatar }, + footer: { text: `• Format: .${format} | Size: ${size}` } + } + }; + + } + +} + +module.exports = AvatarCommand; \ No newline at end of file