在discord.py 中使用 yt_dlp 作为不和谐机器人,音乐提前结束

问题描述 投票:0回答:1

我使用 yt_dlp 模块来为我的 Discord 机器人播放歌曲,以下是我使用的命令

@music.command(name="play", description="Plays the music you specified", aliases=["pl"])
async def play_music(ctx, *, query):
    if not str(ctx.guild.id) in queue.keys(): queue[str(ctx.guild.id)] = []
    with yt_dlp.YoutubeDL(yt) as ydl:
        info = ydl.extract_info(query, download=False)
        video_entry = info.get('entries', [info])[0]
        url = video_entry['url']
        queue[str(ctx.guild.id)].append(url)
        if not ctx.voice_client:
            voice_client = await ctx.author.voice.channel.connect()
        else:
            voice_client = ctx.voice_client
    for i in queue[str(ctx.guild.id)]:
        voice_client.play(discord.FFmpegPCMAudio(url), **{'options': '-vn', "before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5"})
        queue[str(ctx.guild.id)].remove(i)

我搜索了几个解决方案,并得到了

**{'options': '-vn', "before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5"})
作为要传递的kwargs,但它给了我一个错误,即“选项”和“选项之前”是意外的参数

python discord discord.py yt-dlp
1个回答
0
投票
ffmpeg_options = {
   'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
   'options': '-vn'
}

voice_client.play(discord.FFmpegPCMAudio(url), **ffmpeg_options)
© www.soinside.com 2019 - 2024. All rights reserved.