Advertisement
Guest User

Untitled

a guest
Oct 17th, 2016
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js');
  2. const ffmpeg = require('ffmpeg');
  3. const yt = require('ytdl-core');
  4. const spotify = require('spotify-web');
  5. const weather = require('weather');
  6. const client = new Discord.Client();
  7.  
  8.  
  9. const token = 'YOUR TOKEN';
  10. var username = 'VoodButt';
  11. var password = 'rchtoeisnes';
  12. var _YouTubeQ = [];
  13.  
  14.  
  15. client.on('ready',()=>{
  16.     console.log('I am ready!');
  17. });
  18.  
  19. // ON MESSAGE
  20. client.on('message',msg => {
  21.     let prefix="#";
  22.     logMsg(msg.content);
  23.     //Prefix Check
  24.     if(!msg.content.startsWith(prefix))return;
  25.     if(msg.author.bot)return;
  26.     //Command Handling
  27.    
  28.     if(msg.content.startsWith(prefix + 'ping'))
  29.     {
  30.         msg.channel.sendMessage('pong!');
  31.     }
  32.     else if(msg.content.startsWith(prefix + "#foo"))
  33.     {
  34.         msg.channel.sendMessage("bar!");
  35.     }
  36.    
  37.     else if(msg.content === "#init")
  38.     {
  39.         const voiceChannel = msg.member.voiceChannel;
  40.         const streamOptions = { seek : 0 , volume : 1};
  41.         var directorypath = 'path';
  42.         var filename = 'TestSong.mp3';
  43.        
  44.         if(!voiceChannel)
  45.         {
  46.             msg.channel.sendMessage("Not in a voiceChannel");
  47.         }
  48.         else
  49.         {
  50.             voiceChannel.join();
  51.         }
  52.  
  53.     }
  54.  
  55.     else if(msg.content.startsWith("##play"))
  56.     {
  57.         //const init
  58.         const voiceChannel = msg.member.voiceChannel;
  59.         const streamOptions = { seek: 0,volume: 1};
  60.  
  61.         //checks
  62.         if(!voiceChannel)
  63.         {
  64.             msg.channel.sendMessage("Not in a voiceChannel");
  65.             log("Failed to play because the user is not in a voice channel")
  66.         }
  67.         else
  68.         {
  69.             QRepeat(msg);
  70.             /*
  71.             if(_YouTubeQ.length > 0)
  72.             {
  73.                 var link = _YouTubeQ.shift();
  74.                 const stream = yt(link,{filter :'audioonly'});
  75.                 const dispatcher = voiceChannel.connection.playStream(stream,streamOptions);
  76.                 dispatcher.on('end', () => {                    
  77.                 });
  78.             }
  79.             else
  80.             {
  81.                 msg.channel.sendMessage("The Q is empty!");
  82.             }
  83.             */
  84.         }
  85.        
  86.     }
  87.  
  88.     else if(msg.content.startsWith('#add'))
  89.     {
  90.         const yPrefix = "https://www.youtube.com/watch?v=";
  91.         var rest = msg.content.split(" ");
  92.         rest.splice(0,1);
  93.         var link = rest.join(" ");
  94.         _YouTubeQ.push(yPrefix+link);
  95.         msg.channel.sendMessage(link+" added to the Q!");
  96.     }
  97.  
  98.     else if(msg.content.startsWith('#weather'))
  99.     {
  100.  
  101.  
  102.     }
  103. });
  104.  
  105.  
  106.  
  107. //ON MEMBER JOIN
  108. client.on("guildMemberAdd",(server,member)=>
  109. {
  110.     var name = member.username;
  111.     console.log('New user"${member.user.username}" has joined "${server.name}"');
  112.     server.defaultChannel.sendMessage(username+' has joined the server');
  113. });
  114.  
  115.  
  116.  
  117. //ON ERROR
  118. client.on('error',e=>{console.error(e);});
  119.  
  120. client.login(token);
  121.  
  122. //Function section
  123.  
  124. function logMsg(logMessage)
  125. {
  126.     var currentdate = new Date();
  127.     var datetime = currentdate.getDate()+"/"+currentdate.getMonth()+"/"+currentdate.getFullYear()+"@"+currentdate.getHours()+":"+currentdate.getMinutes()+":"+currentdate.getSeconds();
  128.     console.log(datetime+" "+logMessage);
  129. }
  130.  
  131. function reconnect()
  132. {
  133.  
  134. }
  135.  
  136. function QRepeat(msg)
  137. {
  138.     logMsg("Repeat of the _YouTubeQ");
  139.     const voiceChannel = msg.member.voiceChannel;
  140.     const streamOptions = {seek: 0,volume: 1};
  141.     if(voiceChannel)
  142.     {
  143.  
  144.         if(_YouTubeQ.length > 0)
  145.         {
  146.             var link = _YouTubeQ.shift();
  147.             const stream = yt(link, { filter : 'audioonly' } ) ;
  148.             const dispatcher = voiceChannel.connection.playStream(stream,streamOptions);
  149.             dispatcher.on('end',() =>{
  150.                 logMsg("on end event triggered");
  151.                 QRepeat(msg);
  152.             });
  153.         }
  154.         else
  155.         {
  156.             msg.channel.sendMessage("The Q is empty!");
  157.         }
  158.     }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement