You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
902 B
Ruby

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? "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