· 3 months ago · Jul 04, 2025, 12:35 AM
1const { Client, GatewayIntentBits } = require('discord.js');
2const { MoonlinkManager } = require('moonlink.js');
3const { joinVoiceChannel } = require('@discordjs/voice');
4const yts = require('yt-search');
5
6const _c = new Client({ intents: [
7 GatewayIntentBits.Guilds,
8 GatewayIntentBits.GuildVoiceStates,
9 GatewayIntentBits.GuildMessages,
10 GatewayIntentBits.MessageContent
11 ] });
12
13const _n = [{
14 host: '',
15 port: ,
16 secure: ,
17 password: ''
18}];
19
20const _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('');