我想为一个不和谐的机器人流音频,而不是下载文件并从中提取音频文件。我尝试过来自Is there a way to directly stream audio from a youtube video using youtube-dl or pafy library in python 3.7?的代码
发布于 2022-08-02 15:24:15
是的很简单
使用本守则:
ffmpeg_options = {'options': '-vn'}
ydl_opts = {'format': 'bestaudio'}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
song_info = ydl.extract_info(url, download=False)
ctx.voice_client.play(discord.FFmpegPCMAudio(song_info["url"], **ffmpeg_options))
示例:
async def streamx(ctx, url):
voiceChannel = ctx.message.author.voice.channel //get Message Sender Channel. When you want it to join without a seperat function.
await voiceChannel.connect() //same applies to this
ffmpeg_options = {'options': '-vn'}
ydl_opts = {'format': 'bestaudio'}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
song_info = ydl.extract_info(url, download=False)
ctx.voice_client.play(discord.FFmpegPCMAudio(song_info["url"], **ffmpeg_options))
您可以使用来自ydl_opts的文档来调整yt_dlp。
欢迎光临!
https://stackoverflow.com/questions/71187954
复制相似问题