Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 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 PREFIX = '()'
  6. const TOKEN = '.DZ36dA.RiCZ0-xX0l-c8F3iK8FmEhkQRl0'
  7. const client = new Client({ disabledEveryone: true });
  8.  
  9. client.on('warn', console.warn);
  10.  
  11. client.on('error', console.error);
  12.  
  13. client.on('ready', () => console.log('Hey, Just notifiying i have Started myself up, and i\'ll be ready any moment!'));
  14.  
  15. client.on('disconnect', () => console.log('i just disconnected!, making sure you know! i\'ll be reconnecting soon!'));
  16.  
  17. client.on('reconnecting', () => console.log('i am reconnecting now!'));
  18.  
  19. client.on('message', async msg => {
  20. if (msg.author.bot) return undefined;
  21. if (!msg.content.startsWith(PREFIX)) return undefined;
  22. const args = msg.content.split(' ');
  23.  
  24. if (msg.content.startsWith(`${PREFIX}play`)) {
  25. const voiceChannel = msg.member.voiceChannel;
  26. if (!voiceChannel) return msg.channel.send('I\'m Sorry but you need to be in a voicechannel to play music!');
  27. const permissions = voiceChannel.permissionsFor(msg.client.user);
  28. if (!permissions.has('CONNECT')) {
  29. return msg.channel.send('i cannot connect to your voice channel!, make sure i have the right permissions!')
  30. }
  31. if (!permissions.has('SPEAK')) {
  32. return msg.channel.send('i cannot speak in this voice channel!, make sure i have the right permissions!')
  33. }
  34.  
  35. try {
  36. var connection = await voiceChannel.join();
  37. } catch (error) {
  38. console.error(`i could not join the voice channel: ${error}`);
  39. return msg.channel.send(`i could not join the voice channel » Erorr: ${error} «`);
  40. }
  41.  
  42. const dispatcher = connection.playStream(ytdl(args[1]))
  43. .on('end', () => {
  44. console.log('song ended!');
  45. voiceChannel.leave();
  46. })
  47. .on('error', error => {
  48. console.error(error);
  49. });
  50. dispatcher.setVolumeLogarithmic(5 / 5);
  51. }
  52. });
  53.  
  54. client.login(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement