我正在尝试一种可以按命令加入语音聊天,然后播放从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))