I'm making a personal Discord.py
bot and so far it can (sometimes) download a URL and search a term on Youtube and play it, I have been trying to figure out how to actually stream the music instead of downloading it every time, I also tried looking into PyTube but I have not gotten it to work.. using FFMPEG
and youtube_dl
.
@bot.command(name='play', help='Plays a youtube video audio')
async def play(ctx, *, url):
try:
server = ctx.message.guild
voice_channel = server.voice_clients
await ctx.send('attempting...')
async with ctx.typing():
filename = await YTDLSource.from_url(url, loop=bot.loop)
voice_channel.play(discord.FFmpegPCMAudio(source=filename, executable="ffmpeg.exe"))
await ctx.send('**Now playing:** {}'.format(filename))
except:
await ctx.send("Not connected to a Voice Channel or is already playing something.")