Discord.py 和 youtube_dl,“读取错误”和“会话由于某种原因已失效”

2024-01-02

我在使用discord.py和youtube_dl时遇到了这个问题,在队列中播放YouTube链接时会出现一个错误,该错误似乎“滚雪球”到队列中的其他歌曲中。第一首歌曲通常播放得很好,但其余歌曲在很短的时间后就会出现此错误。这是错误:

[tls @ 000001e5618bc200] Error in the pull function.
[matroska,webm @ 000001e5613f9740] Read error
[tls @ 000001e5618bc200] The specified session has been invalidated for some reason.
Last message repeated 1 times
[really long link] I/O error

这是我的 YTDL 源代码和队列函数的代码:

class YTDLSource(discord.PCMVolumeTransformer):
    def __init__(self, source, *, data, volume=0.5):
        super().__init__(source, volume)

        self.data = data

        self.title = data.get('title')
        self.url = data.get('url')

    @classmethod
    async def from_url(cls, url, *, loop=None, stream=False):
        loop = loop or asyncio.get_event_loop()
        data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))

        if 'entries' in data:
            # take first item from a playlist
            data = data['entries'][0]

        filename = data['url'] if stream else ytdl.prepare_filename(data)
        return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data)



queues = {}

class Music(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def q(self, ctx, *, url):
        channel = discord.utils.get(ctx.guild.voice_channels, name="Melodies of Arts")

        if ctx.voice_client is None:
            await channel.connect()


        def check_queue(error):
            if(queues[ctx.guild.id] != []):
                player = queues[ctx.guild.id].pop(0)
                ctx.voice_client.play(player, after=check_queue)     

        async with ctx.typing():
            player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=True)

            if ctx.guild.id in queues:
                queues[ctx.guild.id].append(player)
            else:
                queues[ctx.guild.id] = [player]

            await ctx.send("Video __" + str(player.title) + "__" + " queued at **Position #" + str(len(queues[ctx.guild.id])) + "**", delete_after=15)

            if(not ctx.voice_client.is_playing()):
                ctx.voice_client.play(player, after=check_queue)
                await ctx.send('***Now playing:*** __{}__'.format(player.title), delete_after=10)

Github 问题页面建议“重新下载网址”,但我正在使用 youtube_dl 流式传输链接,并且如果可能的话,我想避免下载视频。无论如何,很多 Github 问题似乎都已经过时了,因此任何与代码相关的解决方案都不再有效。如果我需要提供更多代码/信息,请告诉我!


正如人们常说的:“这真的不是你的错”。这通常发生在 YouTube 方面。

看一眼:Python Youtube ffmpeg 会话已失效 https://stackoverflow.com/questions/54139166/python-youtube-ffmpeg-session-has-been-invalidated

另外,请检查您是否使用以下方式拨打电话:https。 YouTube 不再接受http连接。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Discord.py 和 youtube_dl,“读取错误”和“会话由于某种原因已失效” 的相关文章

随机推荐