mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-10 10:57:08 +02:00
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
const { Command } = require('discord.js-commando');
|
|
const Jimp = require('jimp');
|
|
|
|
module.exports = class InvertCommand extends Command {
|
|
constructor(client) {
|
|
super(client, {
|
|
name: 'invert',
|
|
group: 'avataredit',
|
|
memberName: 'invert',
|
|
description: 'Invert a user\'s avatar colors.',
|
|
args: [
|
|
{
|
|
key: 'user',
|
|
prompt: 'Which user would you like to edit the avatar of?',
|
|
type: 'user'
|
|
}
|
|
]
|
|
});
|
|
}
|
|
|
|
async run(msg, args) {
|
|
if (msg.channel.type !== 'dm')
|
|
if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES'))
|
|
return msg.say('This Command requires the `Attach Files` Permission.');
|
|
const { user } = args;
|
|
const avatarURL = user.avatarURL('png', 2048);
|
|
if (!avatarURL) return msg.say('This user has no avatar.');
|
|
const avatar = await Jimp.read(avatarURL);
|
|
avatar.invert();
|
|
avatar.getBuffer(Jimp.MIME_PNG, (err, buff) => {
|
|
if (err) return msg.say('An Unknown Error Occurred.');
|
|
return msg.channel.send({files: [{attachment: buff}]})
|
|
.catch(err => msg.say(`An Error Occurred: ${err}`));
|
|
});
|
|
}
|
|
};
|