@MondaRinchik

Почему бот не включает музыку?

почему бот выдаёт такие ошибки?
Python 3.11 и делал бота через FFmpeg и youtube-dl

Traceback (most recent call last):
  File "D:\Python\test\venv\Lib\site-packages\discord\ext\commands\core.py", line 229, in wrapped
    ret = await coro(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python\test\main.py", line 19, in play
    vc = await ctx.message.author.voice.channel.connect()
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python\test\venv\Lib\site-packages\discord\abc.py", line 1873, in connect
    voice: T = cls(client, self)
               ^^^^^^^^^^^^^^^^^
  File "D:\Python\test\venv\Lib\site-packages\discord\voice_client.py", line 238, in __init__
    raise RuntimeError("PyNaCl library needed in order to use voice")
RuntimeError: PyNaCl library needed in order to use voice

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\Python\test\venv\Lib\site-packages\discord\ext\commands\bot.py", line 1349, in invoke
    await ctx.command.invoke(ctx)
  File "D:\Python\test\venv\Lib\site-packages\discord\ext\commands\core.py", line 1023, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python\test\venv\Lib\site-packages\discord\ext\commands\core.py", line 238, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: RuntimeError: PyNaCl library needed in order to use voice


Вот исходный код

import discord
from config import token
from discord.ext import commands
from youtube_dl import YoutubeDL

intents = discord.Intents.all()
intents.members = True
intents.presences = True

YDL_OPTIONS = {'format': 'worstaudio/best', 'noplaylist': 'False', 'simulate': 'True', 'preferredquality': '192',
               'preferredcodec': 'mp3', 'key': 'FFmpegExtractAudio'}
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}

bot = commands.Bot(command_prefix='!', intents=intents)


@bot.command()
async def play(ctx, *, url):
    vc = await ctx.message.author.voice.channel.connect()

    with YoutubeDL(YDL_OPTIONS) as ydl:
        if 'https://' in url:
            info = ydl.extract_info(url, download=False)
        else:
            info = ydl.extract_info(f"ytsearch:{url}", download=False)['entries'][0]

    link = info['formats'][0]['url']

    vc.play(discord.FFmpegPCMAudio(executable="ffmpeg\\ffmpeg.exe", source=link, **FFMPEG_OPTIONS))


bot.run(token)
  • Вопрос задан
  • 240 просмотров
Решения вопроса 1
AlexNest
@AlexNest
Работаю с Python/Django
В тексте ошибки предельно ясно написано, что необходимо для корректной работы кода.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы