Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. const { Client } = require('discord.js');
  2. const { Shoukaku } = require('shoukaku');
  3.  
  4. const bot = new Client();
  5. bot.shoukaku = new Shoukaku(bot, [{
  6. name: 'localhost',
  7. host: 'localhost',
  8. port: 2333,
  9. auth: 'youshallnotpass'
  10. }], {
  11. moveOnDisconnect: false,
  12. resumable: true,
  13. resumableTimeout: 30,
  14. reconnectTries: 2,
  15. restTimeout: 10000
  16. });
  17. bot.shoukaku.on('ready', (name) => console.log(`Lavalink Node: ${name} is now connected`));
  18. bot.shoukaku.on('error', (name, error) => console.log(`Lavalink Node: ${name} emitted an error.`, error));
  19. bot.shoukaku.on('close', (name, code, reason) => console.log(`Lavalink Node: ${name} closed with code ${code}. Reason: ${reason || 'No reason'}`));
  20. bot.shoukaku.on('disconnected', (name, reason) => console.log(`Lavalink Node: ${name} disconnected. Reason: ${reason || 'No reason'}`));
  21.  
  22. bot.on('message', async (msg) => {
  23. if (msg.author.bot || !msg.guild) return;
  24. if (!msg.content.startsWith('$play')) return;
  25. if (bot.shoukaku.getPlayer(msg.guild.id)) return;
  26. const args = msg.content.split(' ');
  27. console.log(args);
  28. if (!args[1]) return;
  29. const node = bot.shoukaku.getNode();
  30. let data = await node.rest.resolve(args[1]);
  31. if (!data) return;
  32. if (Array.isArray(data)) data = data[0];
  33. const player = await node.joinVoiceChannel({
  34. guildID: msg.guild.id,
  35. voiceChannelID: msg.member.voice.channelID
  36. });
  37. const cleanFunction = (param) => {
  38. console.log(param);
  39. player.disconnect();
  40. }
  41. player.on('end', cleanFunction);
  42. player.on('closed', cleanFunction);
  43. player.on('error', cleanFunction);
  44. player.on('nodeDisconnect', cleanFunction);
  45. await player.playTrack(data.track);
  46. await msg.channel.send("Now Playing: " + data.info.title);
  47. });
  48. bot.on('ready', () => console.log('Bot is now ready'));
  49. bot.login('NDkzNzU5MDkwMDQwODk3NTU4.Xll0_A.q8mgIRPZmSDFTC_cHZ7lrcw-GdA');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement