Discord.py语音漫游器youtube_dl无效错误

时间:2019-04-18 01:31:59

标签: python discord.py youtube-dl

使用youtube_dl的play命令代码创建python不和谐语音机器人:

@bot.command(pass_context=True, brief="This will play a song 'play [url]'", aliases=['pl'])
async def play(ctx, url:str):
    server = ctx.message.server
    voice_client = bot.voice_client_in(server)
    player = await voice_client.create_ytdl_player(url, after=lambda: check_queue(server.id))
    players[server.id] = player
    player.start()

在不一致的命令中运行该命令后,该歌曲将播放,但是一段时间后,如果链接是youtube视频,则该歌曲将停止播放,并且出现此错误:

[tls @ 000001b884817cc0] Error in the pull function.
[matroska,webm @ 000001b88417a180] Read error
[tls @ 000001b884817cc0] The specified session has been invalidated for some reason.
    Last message repeated 1 times

我已经做了一些研究,我认为这是因为youtube链接已过期。 感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您可以将'-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5'添加为before_options的一部分。

@bot.command(pass_context=True, brief="This will play a song 'play [url]'", aliases=['pl'])
async def play(ctx, url:str):
    server = ctx.message.server
    voice_client = bot.voice_client_in(server)
    player = await voice_client.create_ytdl_player(url, after=lambda: check_queue(server.id), before_options='-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5')
    players[server.id] = player
    player.start()