From d772419227a9e3056845a9ad914e808ca623038f Mon Sep 17 00:00:00 2001
From: loicbersier <loic.bersier1@gmail.com>
Date: Wed, 10 Oct 2018 12:06:37 +0200
Subject: [PATCH] Send youtube vid

---
 commands/fun/youtube.js | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 commands/fun/youtube.js

diff --git a/commands/fun/youtube.js b/commands/fun/youtube.js
new file mode 100644
index 00000000..2d798f89
--- /dev/null
+++ b/commands/fun/youtube.js
@@ -0,0 +1,31 @@
+const { Command } = require('discord.js-commando');
+const fs = require('fs');
+const ytdl = require('ytdl-core')
+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 }) {
+            ytdl(link, { filter: (format) => format.container === 'mp4' })
+            .pipe(fs.createWriteStream('video.mp4'))
+            setTimeout(function(){
+            message.channel.sendFile("./video.mp4")
+            }, 2000)
+            process.on('unhandledRejection',error => message.say('Video too long'));
+        }
+
+}
\ No newline at end of file