Advertisement
Guest User

Untitled

a guest
Jul 31st, 2019
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. const { Client } = require('discord.js');
  2. const { TOKEN, PREFIX } = require('./config');
  3. const ytdl = require('ytdl-core');
  4.  
  5. const client = new Client({ disableEveryone: true });
  6.  
  7. client.on('warn', console.warn);
  8.  
  9.  
  10. client.on('error', console.error);
  11.  
  12. client.on('ready', () => console.log('Yo this ready!!!'));
  13.  
  14. client.on('disconnect', () => console.log('I just disconnected, making sure you now, I will reconnect now'));
  15.  
  16. client.on('reconnecting', () => console.log('I am Reconnecting now!'));
  17.  
  18. client.on('message', async msg => {
  19. if (msg.author.bot) return undefined;
  20. if (!msg.content.startsWith(PREFIX)) return undefined;
  21. const args = msg.content.split(' ');
  22.  
  23. if (msg.content.startsWith(`${PREFIX}play`)) {
  24. const voiceChannel = msg.member.voiceChannel;
  25. if (!voiceChannel) return msg.channel.send('I\'m sorry but you need to be on a voice channel to play music!');
  26. const permissions = voiceChannel.permissionsFor(msg.client.user);
  27. if (!permissions.has('CONNECT')) {
  28. return msg.channel.send('I cannot connect to your voice channel,make sure I have proper permissions!');
  29. }
  30. if (!permissions.has('SPEEK')) {
  31. return msg.channel.send('I cannot speek in this channel, make sure I have proper permissions!');
  32. }
  33.  
  34. try {
  35. var connection = await voiceChannel.join();
  36. } catch (error) {
  37. console.error('I could not join the voice channel : ${error}');
  38. return msg.channel.send('I could not join the voice channel : ${error}');
  39. }
  40.  
  41. const dispatcher = connection.playStream(ytdl(args[1]))
  42. .on('end', () => {
  43. console.log('Song ended!');
  44. voiceChannel.leave();
  45. })
  46. .on('error', error => {
  47. console.error(error);
  48. });
  49. dispatcher.setVolumeLogarithmic(5 / 5);
  50. }
  51.  
  52. });
  53.  
  54. client.login(TOKEN);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement