Advertisement
Guest User

bot music

a guest
Oct 23rd, 2019
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js');
  2. const {
  3.     prefix,
  4.     token,
  5. } = require('./config.json');
  6. const ytdl = require('ytdl-core');
  7.  
  8. const client = new Discord.Client();
  9.  
  10. const queue = new Map();
  11.  
  12. client.once('ready', () => {
  13.     console.log('Ready!');
  14. });
  15.  
  16. client.once('reconnecting', () => {
  17.     console.log('Reconnecting!');
  18. });
  19.  
  20. client.once('disconnect', () => {
  21.     console.log('Disconnect!');
  22. });
  23.  
  24. client.on('message', async message => {
  25.     if (message.author.bot) return;
  26.     if (!message.content.startsWith(prefix)) return;
  27.  
  28.     const serverQueue = queue.get(message.guild.id);
  29.  
  30.     if (message.content.startsWith(`${prefix}play`)) {
  31.         execute(message, serverQueue);
  32.         return;
  33.     } else if (message.content.startsWith(`${prefix}skip`)) {
  34.         skip(message, serverQueue);
  35.         return;
  36.     } else if (message.content.startsWith(`${prefix}stop`)) {
  37.         stop(message, serverQueue);
  38.         return;
  39.     } else if (message.content.startsWith(`${prefix}np`)) {
  40.         message.channel.send(`Now playing: ${serverQueue.songs[0].title}`);
  41.             return;
  42.     } else if (message.content.startsWith(`${prefix}queue`)) {
  43.         message.channel.send(`server queue: ${serverQueue.songs[5].title}`);
  44.             return;
  45.     } else if (message.content.startsWith(`${prefix}help`)) {
  46.                 message.channel.send('commands:');
  47.                 message.channel.send('+play: plays a song');
  48.                 message.channel.send('+skip: skips a song');
  49.                 message.channel.send('+stop:clears the queue and stops the current song');
  50.                 message.channel.send('+np: shows what song is playing');
  51.                 message.channel.send('+queue: shows the song queue');
  52.                 message.channel.send('+countryroads: starts the country road sequence');
  53.                 message.channel.send('+scream: plays a cowboy scream');
  54.                 return;
  55.     } else if (message.content.startsWith(`+scream`)) {
  56.         message.channel.send('AAAAAAAAAAA')
  57.         message.member.voiceChannel.join()
  58.         .then(connection => {
  59.         const dispatcher = connection.playFile('C:\Users\isabe\OneDrive\my music bot\Kirin_J_Callinan_Big_Enough_Ringtone_(by Fringster.com).mp3');
  60.         })
  61.         .catch(console.error);
  62.         return;
  63.     } else if (message.content.startsWith(`${prefix}countryroads`)) {
  64.         message.channel.send(`initiating country roads...`);
  65.         message.channel.send('country roads intitiated ');
  66.         message.channel.send('start the sequence by saying "almost heaven"')
  67.         return;
  68.     } else {
  69.         message.channel.send('You need to enter a valid command!')
  70.     }
  71. });
  72.  
  73. async function execute(message, serverQueue) {
  74.     const args = message.content.split(' ');
  75.  
  76.     const voiceChannel = message.member.voiceChannel;
  77.     if (!voiceChannel) return message.channel.send('You need to be in a voice channel to play music!');
  78.     const permissions = voiceChannel.permissionsFor(message.client.user);
  79.     if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) {
  80.         return message.channel.send('I need the permissions to join and speak in your voice channel!');
  81.     }
  82.  
  83.     const songInfo = await ytdl.getInfo(args[1]);
  84.     const song = {
  85.         title: songInfo.title,
  86.         url: songInfo.video_url,
  87.     };
  88.  
  89.     if (!serverQueue) {
  90.         const queueContruct = {
  91.             textChannel: message.channel,
  92.             voiceChannel: voiceChannel,
  93.             connection: null,
  94.             songs: [],
  95.             volume: 5,
  96.             playing: true,
  97.         };
  98.  
  99.         queue.set(message.guild.id, queueContruct);
  100.  
  101.         queueContruct.songs.push(song);
  102.  
  103.         try {
  104.             var connection = await voiceChannel.join();
  105.             queueContruct.connection = connection;
  106.             play(message.guild, queueContruct.songs[0]);
  107.         } catch (err) {
  108.             console.log(err);
  109.             queue.delete(message.guild.id);
  110.             return message.channel.send(err);
  111.         }
  112.     } else {
  113.         serverQueue.songs.push(song);
  114.         console.log(serverQueue.songs);
  115.         return message.channel.send(`${song.title} has been added to the queue!`);
  116.     }
  117.  
  118. }
  119.  
  120. function skip(message, serverQueue) {
  121.     if (!message.member.voiceChannel) return message.channel.send('You have to be in a voice channel to stop the music!');
  122.     if (!serverQueue) return message.channel.send('There is no song that I could skip!');
  123.     serverQueue.connection.dispatcher.end();
  124. }
  125.  
  126. function stop(message, serverQueue) {
  127.     if (!message.member.voiceChannel) return message.channel.send('You have to be in a voice channel to stop the music!');
  128.     serverQueue.songs = [];
  129.     serverQueue.connection.dispatcher.end();
  130. }
  131.  
  132. function play(guild, song) {
  133.     const serverQueue = queue.get(guild.id);
  134.  
  135.     if (!song) {
  136.         serverQueue.voiceChannel.leave();
  137.         queue.delete(guild.id);
  138.         return;
  139.     }
  140.  
  141.     const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
  142.         .on('end', () => {
  143.             console.log('Music ended!');
  144.             serverQueue.songs.shift();
  145.             play(guild, serverQueue.songs[0]);
  146.         })
  147.         .on('error', error => {
  148.             console.error(error);
  149.         });
  150.     dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
  151. }
  152.  
  153. client.login(token);
  154. client.on('message', message => {
  155.     if (message.content === 'country roads') {
  156.         message.channel.send('take me home');
  157.     } else if (message.content.startsWith(`to the place`)) {
  158.         message.channel.send('I belong');
  159.     }
  160.     else if (message.content.startsWith(`WEST VIRGINIA`)) {
  161.         message.channel.send('MOUNTAIN MOMMA');
  162.     }
  163.     else if (message.content.startsWith(`TO THE PLACE`)) {
  164.         message.channel.send('I BELONG');
  165.     }
  166.     else if (message.content.startsWith(`west virginia`)) {
  167.         message.channel.send('mountain momma');
  168.     }
  169.     else if (message.content === `COUNTRY ROADS`) {
  170.         message.channel.send('TAKE ME HOME');
  171.     }
  172.     else if (message.content.startsWith(`i hear her voice in the morning`)) {
  173.         message.channel.send('hour she calls me');
  174.     }
  175.     else if (message.content.startsWith(`I HEAR HER VOICE IN THE MORNING`)) {
  176.         message.channel.send('HOUR SHE CALLS ME');
  177.     }
  178.     else if (message.content.startsWith(`RADIO REMINDS ME OF MY HOME FAR AWAY`)) {
  179.         message.channel.send('DRIVING DOWN THE ROAD I GET A FEELING I SHOULD HAVE BEEN HOME YESTERDAY, YESTERDAY');
  180.     }
  181.     else if (message.content.startsWith(`radio reminds me of my home far away`)) {
  182.         message.channel.send('drivin down the road I get a feeling I should have been home yesterday, yesterday');
  183.     }
  184.     else if (message.content.startsWith(`all my memories`)) {
  185.         message.channel.send("gather 'round her");
  186.     }
  187.     else if (message.content.startsWith(`ALL MY MEMORIES`)) {
  188.         message.channel.send("GATHER 'ROUND HER");
  189.     }
  190.     else if (message.content.startsWith(`MINER`)) {
  191.         message.channel.send('STRANGER TO BLUE WATER');
  192.     }
  193.     else if (message.content.startsWith(`miner`)) {
  194.         message.channel.send('stranger to blue water');
  195.     }
  196.     else if (message.content.startsWith(`dark and dusty`)) {
  197.         message.channel.send('painted on the sky');
  198.     }
  199.     else if (message.content.startsWith(`DARK AND DUSTY`)) {
  200.         message.channel.send('PAINTED ON THE SKY');
  201.     }
  202.     else if (message.content.startsWith(`misty taste of moonshine`)) {
  203.         message.channel.send('teardrop in my eye');
  204.     }
  205.     else if (message.content.startsWith(`MISTY TASTE OF MOONSHINE`)) {
  206.         message.channel.send('TEARDROP IN MY EYE');
  207.     }
  208.     else if (message.content.startsWith(`almost heaven`)) {
  209.         message.channel.send('West Virginia');
  210.     }
  211.     else if (message.content.startsWith(`blue ridge mountains`)) {
  212.         message.channel.send('Shenandoah River');
  213.     }
  214.     else if (message.content.startsWith(`life is old there`)) {
  215.         message.channel.send('older than the trees');
  216.     }
  217.     else if (message.content.startsWith(`younger than the mountains`)) {
  218.         message.channel.send('blowing like a breeze');
  219.     }
  220.     else if (message.content === `take me home,`) {
  221.         message.channel.send('down country roads');
  222.     }
  223.     else if (message.content === `Take me home,`) {
  224.         message.channel.send('down country roads');
  225.     }
  226.     else if (message.content === `TAKE ME HOME,`) {
  227.         message.channel.send('DOWN COUNTRY ROADS');
  228.     }
  229.     else if (message.content === `radio reminds of my home far away,`) {
  230.         message.channel.send('drivin down the road I get a feeling I should have been home yesterday, yesterday');
  231.     }
  232.     else if (message.content === `RADIO REMINDS OF MY HOME FAR AWAY,`) {
  233.         message.channel.send('DRIVING DOWN THE ROAD I GET A FEELING I SHOULD HAVE BEEN HOME YESTERDAY, YESTERDAY');
  234.     }
  235.     else if (message.content === `${prefix}server`) {
  236.         message.channel.send(`This server's name is: ${message.guild.name}`);
  237.   }
  238. });
  239. client.on('message', message => {
  240.   if (message.content === `TAKE ME HOME`) {
  241.   message.channel.send('COUNTRY ROADS');
  242. }})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement