@bot.command() async def play(ctx, url: str): if not ctx.author.voice: return await ctx.send("Вы не подключены к голосовому каналу!") voice_channel = ctx.author.voice.channel if ctx.voice_client is None: vc = await voice_channel.connect() else: await ctx.voice_client.move_to(voice_channel) vc = ctx.voice_client
video = pafy.new(url) best = video.getbestaudio() source = await discord.FFmpegOpusAudio.from_probe(best.url, method='fallback') vc.play(source)
@bot.command() async def leave(ctx): if ctx.voice_client: await ctx.guild.voice_client.disconnect() else: await ctx.send("Бот не подключен к голосовому каналу.")
При запуске команды бот пишет ошибку
Traceback (most recent call last): File "/home/runner/Discord-bot/.pythonlibs/lib/python3.10/site-packages/discord/ext/commands/core.py", line 235, in wrapped ret = await coro(*args, **kwargs) File "/home/runner/Discord-bot/main.py", line 264, in play video = pafy.new(url) File "/home/runner/Discord-bot/.pythonlibs/lib/python3.10/site-packages/pafy/pafy.py", line 124, in new return Pafy(url, basic, gdata, size, callback, ydl_opts=ydl_opts) File "/home/runner/Discord-bot/.pythonlibs/lib/python3.10/site-packages/pafy/backend_youtube_dl.py", line 31, in __init__ super(YtdlPafy, self).__init__(*args, **kwargs) File "/home/runner/Discord-bot/.pythonlibs/lib/python3.10/site-packages/pafy/backend_shared.py", line 97, in __init__ self._fetch_basic() File "/home/runner/Discord-bot/.pythonlibs/lib/python3.10/site-packages/pafy/backend_youtube_dl.py", line 50, in _fetch_basic self._rating = self._ydl_info['average_rating'] KeyError: 'average_rating'
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/home/runner/Discord-bot/.pythonlibs/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 1350, in invoke await ctx.command.invoke(ctx) File "/home/runner/Discord-bot/.pythonlibs/lib/python3.10/site-packages/discord/ext/commands/core.py", line 1029, in invoke await injected(*ctx.args, **ctx.kwargs) # type: ignore File "/home/runner/Discord-bot/.pythonlibs/lib/python3.10/site-packages/discord/ext/commands/core.py", line 244, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'average_rating'
Поставил только часть кода потому что в полном коде много ключей от OpenAI и других нейросетей