0

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.")
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Happy Lama
  • 31
  • 6
  • You can check something similar [here](https://stackoverflow.com/questions/66610012/discord-py-streaming-youtube-live-into-voice). – ChaoticNebula Sep 13 '21 at 13:49
  • There is [an example](https://github.com/Rapptz/discord.py/blob/45d498c1b76deaf3b394d17ccf56112fa691d160/examples/basic_voice.py#L77) on discord.py repo. Could you please expand on 'I have not gotten it to work'? Does it give an error? Does it join the voice channel? – Nevus Sep 13 '21 at 13:50
  • The bot starts fine, but it just sends a message saying "Not connected to a Voice Channel..." but it is connected to a voice channel @SuvenPandey – Happy Lama Sep 13 '21 at 15:07
  • You can [print the exception](https://stackoverflow.com/a/1483488/10168590) for more info. The error message should be self-explanatory. – Nevus Sep 13 '21 at 15:32
  • `Guild.voice_clients` isn't a thing. you are most likely using `Guild.voice_client` without the s – Wasi Master Sep 13 '21 at 16:53

0 Answers0