avatar command

This commit is contained in:
Erik 2022-04-29 20:05:53 +03:00
parent 8bd91e6a16
commit 2f9218ac47
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -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;