Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // install ytdl-core before running this!
  2. // npm install --save ytdl-core
  3. const Discord = require("discord.js");
  4. const yt = require('ytdl-core');
  5. const client = new Discord.Client();
  6. client.login(" Y o u r   B o t   T o k e n ");
  7.  
  8. client.on('message', message => {
  9.   if (message.content.startsWith('++play')) {
  10.     const voiceChannel = message.member.voiceChannel;
  11.     if (!voiceChannel) {
  12.       return message.reply(`Please be in a voice channel first!`);
  13.     }
  14.     voiceChannel.join()
  15.       .then(connnection => {
  16.         let stream = yt("https://www.youtube.com/watch?v=dQw4w9WgXcQ", {audioonly: true});
  17.         const dispatcher = connnection.playStream(stream);
  18.         dispatcher.on('end', () => {
  19.           voiceChannel.leave();
  20.         });
  21.       });
  22.   }
  23. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement