galactic-bot/structure/client/components/commands/utility/Avatar.js

69 lines
1.9 KiB
JavaScript
Raw Normal View History

const { Command } = require('../../../../interfaces/');
class AvatarCommand extends Command {
constructor(client) {
super(client, {
name: 'avatar',
module: 'utility',
aliases: [
'pfp'
],
arguments: [
{
name: 'size',
type: 'INTEGER',
types: ['VERBAL', 'FLAG'],
options: [ 16, 32, 64, 128, 256, 512, 1024, 2048 ],
default: 512,
required: true
},
{
name: 'format',
type: 'STRING',
types: ['VERBAL', 'FLAG'],
options: [ 'webp', 'png', 'jpeg', 'jpg', 'gif' ],
default: 'webp',
required: true
}
]
});
this.client = client;
}
async execute(message, { params, args }) {
let user = params.length ? await this.client.resolver.resolveUser(params[0]) : message.author;
if (!user) user = message.author;
let avatar = null;
try {
avatar = user.displayAvatarURL({ format: args.format?.value || 'webp', size: args.size?.value || 128, dynamic: true });
} catch(error) {
message.respond(message.format('C_AVATAR_FORMATERROR'), { emoji: 'failure' });
return undefined;
}
return message.embed({
author: {
name: user.tag,
icon_url: user.displayAvatarURL()
},
description: `[**Link to Image**](${avatar})`,
image: {
url: avatar
},
footer: {
text: `• Format: .${args.format?.value || 'webp'} | Size: ${args.size?.value || '128'}`
}
});
}
}
module.exports = AvatarCommand;