Advertisement
BETAlwrd

music moonlink/lavalink

Jul 3rd, 2025
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Client, GatewayIntentBits } = require('discord.js');
  2. const { MoonlinkManager } = require('moonlink.js');
  3. const { joinVoiceChannel } = require('@discordjs/voice');
  4. const yts = require('yt-search');
  5.  
  6. const _c = new Client({ intents: [
  7.     GatewayIntentBits.Guilds,
  8.     GatewayIntentBits.GuildVoiceStates,
  9.     GatewayIntentBits.GuildMessages,
  10.     GatewayIntentBits.MessageContent
  11.   ] });
  12.  
  13. const _n = [{
  14.   host: '',
  15.   port: ,
  16.   secure: ,
  17.   password: ''
  18. }];
  19.  
  20. const _m = new MoonlinkManager(_n, {}, (g, p) => {
  21.   _c.guilds.cache.get(g)?.shard.send(JSON.parse(p));
  22. });
  23.  
  24. _c.once('ready', () => {
  25.   _m.init(_c.user.id);
  26.   console.log('bot has ready on djs');
  27. });
  28.  
  29. _c.ws.on('VOICE_SERVER_UPDATE', d => _m.packetUpdate(d));
  30. _c.ws.on('VOICE_STATE_UPDATE', d => _m.packetUpdate(d));
  31.  
  32. _c.on('messageCreate', async m => {
  33.   if (!m.content.startsWith('-') || m.author.bot) return;
  34.  
  35.   const [_cmd, ..._a] = m.content.slice(1).trim().split(/ +/g);
  36.   const _vc = m.member.voice.channel;
  37.   const _p = _m.players.get(m.guild.id) || _m.players.create({ guildId: m.guild.id, voiceChannel: _vc.id, textChannel: m.channel.id });
  38.  
  39.   if (_cmd === 'p') {
  40.     if (!_vc) return m.react('❌');const _q = _a.join(' ');
  41.     const _r = await yts(_q);const _t = _r.videos[0];
  42.   if (!_t) return m.react('❌');if (!_p.connected) joinVoiceChannel({ channelId: _vc.id, guildId: m.guild.id, adapterCreator: m.guild.voiceAdapterCreator });
  43.     _p.play({ track: (await _p.search(_t.url, m.author)).tracks[0] });m.reply("**🎶** :"+_t.title);}
  44.   if (_cmd === 's') {if (!_p || !_p.queue.length) return m.react('❌');_p.skip();m.react(':white_check_mark:');}
  45.   if (_cmd === 'dc') {if (!_p) return m.react('❌');_p.destroy();m.react(':white_check_mark:');}
  46.   if (_cmd === 'np') {if (!_p || !_p.current) return m.react('❌');
  47.     m.reply(`now: **${_p.current.title}**`);
  48.   }
  49. });
  50.  
  51. _c.login('');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement