A
A
Artyom2021-02-26 01:51:03
Python
Artyom, 2021-02-26 01:51:03

How to use the youtube_dl library to play audio without downloading?

@client.command()
@commands.has_permissions(administrator = True)
async def connect(ctx):
    if(ctx.author.voice):
        voice = await ctx.author.voice.channel.connect()
        await ctx.send("Подключён") 
        url = "https://youtu.be/rLeQSd7R-jU"
        source = FFmpegPCMAudio(url)
        voice.play(source)
    else:
        await ctx.send("Что-то пошло не так!")

I need a type of this kind of playback but only without downloading (for example, broadcasting). As I understand it, first you need to set the playback method, but I don’t know how.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeniy _, 2021-02-26
@artemgoruchev

FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
youdl_opts = {'format': 'bestaudio'}
with youtube_dl.YoutubeDL(youdl_opts) as youdl:
    info = youdl.extract_info(video_link, download=False)
    URL = info['formats'][0]['url']
voice = get(self.bot.voice_clients, guild=ctx.guild)
voice.play(discord.FFmpegPCMAudio(URL, **FFMPEG_OPTIONS))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question