From d664e98909e297bd7a0a766de22d957cdf78fde9 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sat, 13 Aug 2022 17:30:14 +0300 Subject: [PATCH] flag to fetch user's banner with avatar command --- .../en_gb/commands/en_gb_utility.lang | 3 +++ .../components/commands/utility/Avatar.js | 24 +++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/localization/en_gb/commands/en_gb_utility.lang b/src/localization/en_gb/commands/en_gb_utility.lang index f407399..7fd36b6 100644 --- a/src/localization/en_gb/commands/en_gb_utility.lang +++ b/src/localization/en_gb/commands/en_gb_utility.lang @@ -8,6 +8,9 @@ Use the member option to display their server avatar. [COMMAND_AVATAR_FORMATERROR] Unable to find an avatar with those arguments, try a different size or format. +[COMMAND_AVATAR_NOBANNER] +User doesn't have a banner. + [COMMAND_REMIND_CONFIRM] Will remind you about '{reminder}' in {time} diff --git a/src/structure/components/commands/utility/Avatar.js b/src/structure/components/commands/utility/Avatar.js index 53404dc..761c102 100644 --- a/src/structure/components/commands/utility/Avatar.js +++ b/src/structure/components/commands/utility/Avatar.js @@ -11,7 +11,7 @@ class AvatarCommand extends SlashCommand { name: 'size', description: 'The width/height value', // type: 'INTEGER', - choices: [16, 32, 64, 128, 256, 512, 1024, 2048].map((i) => { + choices: [16, 32, 64, 128, 256, 512, 1024, 2048, 4096].map((i) => { return { name: `${i}`, value: `${i}` }; }), flag: true @@ -32,19 +32,29 @@ class AvatarCommand extends SlashCommand { description: 'Use this for the user\'s server avatar', type: 'MEMBER', flag: true + }, { + name: 'banner', + type: 'BOOLEAN', + description: 'Fetch the user\'s banner', + flag: true, valueOptional: true, defaultValue: true }] }); } - async execute(invoker, { format, size, user, member }) { + async execute(invoker, { format, size, user, member, banner }) { - const target = member?.value || user?.value || invoker.member || invoker.author; + const _target = member?.value || user?.value || invoker.member || invoker.author; + const target = await _target.fetch(); format = format?.value || 'webp'; size = parseInt(size?.value || 256); + banner = banner?.value || false; - let avatar = null; + let imageUrl = null; try { - avatar = target.displayAvatarURL({ format, size, dynamic: true }); + if (banner) { + imageUrl = target.bannerURL({ format, size, dynamic: true }); + if(!target.banner) return { emoji: 'failure', index: 'COMMAND_AVATAR_NOBANNER' }; + } else imageUrl = target.displayAvatarURL({ format, size, dynamic: true }); } catch (err) { return { emoji: 'failure', index: 'COMMAND_AVATAR_FORMATERROR' }; } @@ -52,8 +62,8 @@ class AvatarCommand extends SlashCommand { return { embed: { title: target.user?.tag || target.tag, - description: `[**Link**](${avatar})`, - image: { url: avatar }, + description: `[**Link**](${imageUrl})`, + image: { url: imageUrl }, footer: { text: `• Format: .${format} | Size: ${size}` } } };