//play.js const ytdl = require('ytdl-core'); const ytSearch =require('yt-search'); const { description, execute } = require('./clear'); const message = require('../events/guild/message'); const queue = new Map(); module.exports = { name: 'play', aliases: ['skip', 'stop'], description: 'Musik bot basic commands', async execute(message, args, cmd, client, Discord){ const voice_channel = message.member.voice.channel; if (!voice_channel) return message.channel.send('Du musst dafür in einem voicechannel sein, du depp!'); const permissions = voice_channel.permissionsFor(message.client.user); if (!permissions.has('CONNECT')) return message.channel.send('Du musst dafür channel connecten dürfen, du saudepp!'); if (!permissions.has('SPEAK')) return message.channel.send('lern erstmal das reden, du depp!'); const server_queue = queue.get(message.guild.id) if(cmd=== 'play'){ if(!args.length) return message.channel.send('must schon n lied eingeben!'); let song = {}; if(ytdl.validateURL(args[0])){ const song_info = await ytdl.getInfo(args[0]); song = {title: song_info.videoDetails.title, url: song_info.videoDetails.video_url} }else{ const video_finder = async (query) =>{ const videoResult = await ytSearch(query); return(videoResult.videos.length >1) ? videoResult.videos[0] : null; } const video = await video_finder(args.join(' ')); if (video){ song = {title: video.title, url: video.video_url} }else { return message.channel.send('kein lied g´funden du saupreis'); } } if (!server_queue){ const queue_constructor = { voice_channel: voice_channel, text_channel: message.channel, connection: null, songs: [] } queue.set(message.guild.id, queue_constructor); queue_constructor.songs.push(song); try { const connection= await voice_channel.join(); queue_constructor.connection = connection video_player(message.guild, queue_constructor.songs[0]); } catch (err) { queue.delete(message.guild.id); message.channel.send('Fehler beim connecten, Costas der Depp?'); throw err; } }else { server_queue.songs.push(song); } }else if(cmd=== 'skip')skip_song(message, server_queue); else if(cmd=== 'stop')stop_song(message, server_queue); } } const video_player = async (guild, song) => { const song_queue = queue.get(guild.id); if(!song) { song_queue.voice_channel.leave(); queue.delete(guild.id); return; } const stream = ytdl(song.url, {filter:'audioonly'}); song_queue.connection.play(stream, {seek: 0, volume: 0.5}) .on('finish', () => { song_queue.songs.shift(); video_player(guild, song_queue.songs[0]); }); await song_queue.text_channel.send(`Now playing **${song.title}**`); } const skip_song = (message, server_queue) => { if(!message.member.voice.channel) return message.channel.send('Du musst dafür in einem voicechannel sein, du depp!'); if(!server_queue) return message.channel.send('Keine Songs in der queue'); server_queue.connection.dispatcher.end(); message.channel.send('weil du es bist'); } const stop_song = (message, server_queue) => { if(!message.member.voice.channel) return message.channel.send('Du musst dafür in einem voicechannel sein, du depp!'); server_queue.songs = []; server_queue.connection.dispatcher.end(); message.channel.send('**Bruder muss los**'); } //message.js module.exports = (Discord, client, message) => { const prefix = '-'; if(!message.content.startsWith(prefix) || message.author.bot) return; const args = message.content.slice(prefix.length).split(/ +/); const cmd = args.shift().toLowerCase(); const command = client.commands.get(cmd) || client.commands.find(a => a.aliases && a.aliases.includes(cmd)); if(command) command.execute(message, args, cmd, client, Discord); }