import discord
from discord.ext import commands
from youtube_dl import YoutubeDL
import config
YDL_OPTIONS = {'format': 'worstaudio/best', 'noplaylist': 'False', 'simulate': 'True', 'key': 'FFmpegExtractAudio'}
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print("Бот в сети!")
@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: print("нужна сслыка")
link = info['formats'][0]['url']
vc.play(discord.FFmpegPCMAudio(executable="ffmpeg\\ffmpeg.exe", source=link, **FFMPEG_OPTIONS))
bot.run(config.token)
Хотел сделать своего бота который проигрывает звук с видео из ютуба, но выдает ошибку ниже.
[2024-04-18 17:00:05] [ERROR ] discord.ext.commands.bot: Ignoring exception in command play
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\DisBot\.venv\lib\site-packages\discord\ext\commands\core.py", line 235, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\user\PycharmProjects\DisBot\musica.py", line 20, in play
vc = await ctx.message.author.voice.channel.connect()
File "C:\Users\user\PycharmProjects\DisBot\.venv\lib\site-packages\discord\abc.py", line 1898, in connect
voice: T = cls(client, self)
File "C:\Users\user\PycharmProjects\DisBot\.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 "C:\Users\user\PycharmProjects\DisBot\.venv\lib\site-packages\discord\ext\commands\bot.py", line 1350, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\user\PycharmProjects\DisBot\.venv\lib\site-packages\discord\ext\commands\core.py", line 1029, in invoke
await injected(*ctx.args, **ctx.kwargs) # type: ignore
File "C:\Users\user\PycharmProjects\DisBot\.venv\lib\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: RuntimeError: PyNaCl library needed in order to use voice