def playMusic(bot, bang) bot.message(start_with: "#{bang}Play ") do |event| message = event.content author = event.author voice_channel = author.voice_channel.id server = event.server bot.voice_connect(voice_channel) arguments = message.sub("#{bang}Play ", '').split.first #event.voice.play_file('./example.mp3') if arguments.include? "&list" event.respond "Do not play playlists. They are unsupported." elsif arguments.include? "youtu" event.respond "Playing song! This may take some time." tempFile = Dir::Tmpname.create(['youtubedlruby-', '.mp3']) {} cmd = "yt-dlp --extract-audio --audio-format mp3 --output " + tempFile + " " + arguments system(cmd) event.voice.play_file(tempFile) File.delete(tempFile) if File.exist?(tempFile) bot.voice_destroy(server) event.respond "Done playing!" else event.respond "Invalid youtube link!" end end bot.message(with_text: "#{bang}Play") do |event| event.respond "Please provide youtube link!" end end