Discord.py将来自youtube的播放音频重写为语音聊天

时间:2020-11-06 03:31:23

标签: python ffmpeg youtube discord discord.py

我正在尝试一种可以按命令加入语音聊天,然后播放从youtube视频中提取的音频的漫游器。我不知道该怎么做,我得到的所有代码似乎都行不通。有谁知道该怎么办?

@client.command() async def play(ctx):
channel = ctx.message.author.voice.channel
voice_client = await channel.connect()

opts = {'format': 'bestaudio'}
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
with youtube_dl.YoutubeDL(opts) as ydl:
    song_info = ydl.extract_info('video', download=False)
    URL = song_info['formats'][0]['url']
voice_client.play(FFmpegPCMAudio(URL, **FFMPEG_OPTIONS))

0 个答案:

没有答案