diff --git a/commands/fun/youtube.js b/commands/fun/youtube.js deleted file mode 100644 index 04d70f1..0000000 --- a/commands/fun/youtube.js +++ /dev/null @@ -1,40 +0,0 @@ -const { Command } = require('discord.js-commando'); -const fs = require('fs'); -const ytdl = require('ytdl-core') -const blacklist = require('../../json/blacklist.json') - -module.exports = class youtubeCommand extends Command { - constructor(client) { - super(client, { - name: 'youtube', - group: 'fun', - memberName: 'youtube', - description: `Send a youtube link as mp4`, - args: [ - { - key: 'link', - prompt: 'Wich youtube link would you like to send', - type: 'string', - default: 'https://www.youtube.com/watch?v=6n3pFFPSlW4' - } - ] - }); - } - - async run(message, { link }) { - if(blacklist[message.author.id]) - return message.channel.send("You are blacklisted") - if(link.includes("http") || link.includes("www")) { - ytdl(link, { filter: (format) => format.container === 'mp4' }) - .pipe(fs.createWriteStream('video.mp4')) - setTimeout(function(){ - message.channel.sendFile("./video.mp4") - .catch(error => { - message.say('Video too long') - }) - }, 5000) - } else - message.say("You need to input a valid youtube link") - } - -} \ No newline at end of file diff --git a/commands/utility/youtube.js b/commands/utility/youtube.js new file mode 100644 index 0000000..c8c13bc --- /dev/null +++ b/commands/utility/youtube.js @@ -0,0 +1,40 @@ +const { Command } = require('discord.js-commando'); +const fs = require('fs'); +const youtubedl = require('youtube-dl'); +const blacklist = require('../../json/blacklist.json'); +const { fbuser, fbpasswd } = require('../../config.json'); + +module.exports = class youtubeCommand extends Command { + constructor(client) { + super(client, { + name: 'youtube', + group: 'utility', + memberName: 'youtube', + description: `Download any video from the link you provided.`, + args: [ + { + key: 'link', + prompt: 'Wich video would you like to download?', + type: 'string', + default: 'https://www.youtube.com/watch?v=6n3pFFPSlW4' + } + ] + }); + } + + async run(message, { link }) { + if(blacklist[message.author.id]) + return message.channel.send("You are blacklisted") + if(link.includes("http") || link.includes("www")) { + message.say('Downloading...') + let video = youtubedl(link, [`--username=${fbuser}`,`--password=${fbpasswd}`]) + video.pipe(fs.createWriteStream('video.mp4')) + video.on('end', function() { + message.channel.send({files: ["./video.mp4"]}) + .catch(error => message.say('An error has occured, the file might be too big or i cant download the link you provided')) + }) + } else + message.say("You need to input a valid link") + } + +} \ No newline at end of file