Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Client } = require('discord.js');
- const { Shoukaku } = require('shoukaku');
- const bot = new Client();
- bot.shoukaku = new Shoukaku(bot, [{
- name: 'localhost',
- host: 'localhost',
- port: 2333,
- auth: 'youshallnotpass'
- }], {
- moveOnDisconnect: false,
- resumable: true,
- resumableTimeout: 30,
- reconnectTries: 2,
- restTimeout: 10000
- });
- bot.shoukaku.on('ready', (name) => console.log(`Lavalink Node: ${name} is now connected`));
- bot.shoukaku.on('error', (name, error) => console.log(`Lavalink Node: ${name} emitted an error.`, error));
- bot.shoukaku.on('close', (name, code, reason) => console.log(`Lavalink Node: ${name} closed with code ${code}. Reason: ${reason || 'No reason'}`));
- bot.shoukaku.on('disconnected', (name, reason) => console.log(`Lavalink Node: ${name} disconnected. Reason: ${reason || 'No reason'}`));
- bot.on('message', async (msg) => {
- if (msg.author.bot || !msg.guild) return;
- if (!msg.content.startsWith('$play')) return;
- if (bot.shoukaku.getPlayer(msg.guild.id)) return;
- const args = msg.content.split(' ');
- console.log(args);
- if (!args[1]) return;
- const node = bot.shoukaku.getNode();
- let data = await node.rest.resolve(args[1]);
- if (!data) return;
- if (Array.isArray(data)) data = data[0];
- const player = await node.joinVoiceChannel({
- guildID: msg.guild.id,
- voiceChannelID: msg.member.voice.channelID
- });
- const cleanFunction = (param) => {
- console.log(param);
- player.disconnect();
- }
- player.on('end', cleanFunction);
- player.on('closed', cleanFunction);
- player.on('error', cleanFunction);
- player.on('nodeDisconnect', cleanFunction);
- await player.playTrack(data.track);
- await msg.channel.send("Now Playing: " + data.info.title);
- });
- bot.on('ready', () => console.log('Bot is now ready'));
- bot.login('NDkzNzU5MDkwMDQwODk3NTU4.Xll0_A.q8mgIRPZmSDFTC_cHZ7lrcw-GdA');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement