From 4fd695c655ee8d347bb794d11250fd1883fda222 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 2 May 2017 01:36:51 +0000 Subject: [PATCH] Greyscale --- commands/avataredit/greyscale.js | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 commands/avataredit/greyscale.js diff --git a/commands/avataredit/greyscale.js b/commands/avataredit/greyscale.js new file mode 100644 index 00000000..25769bb9 --- /dev/null +++ b/commands/avataredit/greyscale.js @@ -0,0 +1,33 @@ +const { Command } = require('discord.js-commando'); +const Jimp = require('jimp'); + +module.exports = class GreyscaleCommand extends Command { + constructor(client) { + super(client, { + name: 'greyscale', + group: 'avataredit', + memberName: 'greyscale', + description: 'Greyscale your 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.greyscale(); + avatar.getBuffer(Jimp.MIME_PNG, (err, buff) => { + if (err) return msg.say('An Unknown Error Occurred.'); + return msg.channel.send({files: [{attachment: buff}]}); + }); + } +};