From 188aff48d3ab63b965c77effc256d74e75a65e27 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Thu, 10 Oct 2019 01:30:34 +0200 Subject: [PATCH] remove.bg --- commands/utility/removebg.js | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 commands/utility/removebg.js diff --git a/commands/utility/removebg.js b/commands/utility/removebg.js new file mode 100644 index 00000000..068819fe --- /dev/null +++ b/commands/utility/removebg.js @@ -0,0 +1,46 @@ +const { Command } = require('discord-akairo'); +const { removebgAPI } = require('../../config.json'); +const removd = require('removd'); +const os = require('os'); + +class removebgCommand extends Command { + constructor() { + super('removebg', { + aliases: ['removebg'], + category: 'utility', + args: [ + { + id: 'image', + type: 'string' + } + ], + description: { + content: 'Remove the background from the image you send using remove.bg', + usage: '', + examples: [''] + } + }); + } + + async exec(message, args) { + let Attachment = (message.attachments).array(); + let url = args.image; + if (Attachment[0] && !args.image) { + url = Attachment[0].url; + } + const outputFile = `${os.tmpdir()}/rempvebg.png`; + const done = await removd.url({ + apikey: removebgAPI, + destination: outputFile, + source: url + }); + if (done && !done.error) { + return message.channel.send({files: [outputFile]}); + } else { + console.error(done); + return message.channel.send('Oh no! an error just occured!'); + } + } +} + +module.exports = removebgCommand; \ No newline at end of file