const Discord = require('discord.js'); const ytdl = require('ytdl-core'); const client = new Discord.Client({ intents: [ Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMessages, Discord.GatewayIntentBits.MessageContent ] }) const token = 'MTA1NDUwMTA1NTI1OTQ4MDEzNg.GGOpkG.xRaiMaqm5n7Ma6Y01blmlOksAGqpZmVbwr50c8'; const prefix = '!'; // prefix dla poleceń bota client.on('ready', () => { console.log('Bot jest gotowy do działania!'); }); client.on('messageCreate', async message => { if (!message.content.startsWith(prefix) || message.author.bot) return; // ignorowanie poleceń od innych botów i poleceń bez prefixa const args = message.content.slice(prefix.length).trim().split(/ +/); const command = args.shift().toLowerCase(); if (command === 'play') { const voiceChannel = message.member.voice.channel; if (!voiceChannel) return message.reply('Nie jesteś podłączony do kanału głosowego!'); const permissions = voiceChannel.permissionsFor(message.client.user); if (!permissions.has('Connect') || !permissions.has('Speak')) { return message.reply('Nie posiadam odpowiednich uprawnień, aby połączyć się i rozmawiać na kanale głosowym!'); } if (!args.length) return message.reply('Nie podałeś linku do muzyki!'); const connection = await voiceChannel.join(); const stream = ytdl(args[0], { filter: 'audioonly' }); const dispatcher = connection.play(stream); dispatcher.on('finish', () => voiceChannel.leave()); } else if (command === 'stop') { const voiceChannel = message.member.voice.channel; if (!voiceChannel) return message.reply('Nie jesteś podłączony do kanału głosowego!'); voiceChannel.leave(); } }); client.login(token);