gpt4 book ai didi

python - discord.py和youtube_dl, “Read error”和 “The session has been invalidated for some reason”

转载 作者:行者123 更新时间:2023-12-03 05:53:19 29 4
gpt4 key购买 nike

我一直在使用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 Session Has Been Invalidated

另外,检查您是否使用https进行了调用。 YouTube不再接受http连接。

关于python - discord.py和youtube_dl, “Read error”和 “The session has been invalidated for some reason”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58892635/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com