Музыкальный бот для Discord на Python
Написал музыкального бота, который при команде -play (link)
входит в голосовой канал, но не включает музыку, а выдает ошибку
Код:
import discord
from discord.ext import commands
import pafy
import logging
import youtube_dl
logging.basicConfig(filename='bot.log', level=logging.INFO)
TOKEN = 'token'
PREFIX = '-'
intents = discord.Intents.all()
intents.members = True
bot = commands.Bot(command_prefix=PREFIX, intents=intents)
@bot.event
async def on_ready():
print(f'Logged in as {bot.user}')
@bot.event
async def on_message(message):
if message.content.lower() == 'привет':
await message.channel.send('Привет!')
await bot.process_commands(message)
@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("Бот не подключен к голосовому каналу.")
logging.info('Bot Online')
bot.run(TOKEN)
Ошибка:
ERROR discord.ext.commands.bot Ignoring exception in command play
Traceback (most recent call last):
File "a:\Work\piton\discord3\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 815, in wrapper
return func(self, *args, **kwargs)
File "a:\Work\piton\discord3\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 836, in __extract_info
ie_result = ie.extract(url)
File "a:\Work\piton\discord3\venv\lib\site-packages\youtube_dl\extractor\common.py", line 534, in extract
ie_result = self._real_extract(url)
File "a:\Work\piton\discord3\venv\lib\site-packages\youtube_dl\extractor\youtube.py", line 1794, in _real_extract
'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id') if owner_profile_url else None,
File "a:\Work\piton\discord3\venv\lib\site-packages\youtube_dl\extractor\common.py", line 1012, in _search_regex
raise RegexNotFoundError('Unable to extract %s' % _name)
youtube_dl.utils.RegexNotFoundError: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "a:\Work\piton\discord3\venv\lib\site-packages\discord\ext\commands\core.py", line 229, in wrapped
ret = await coro(*args, **kwargs)
File "a:\Work\piton\discord3\main.py", line 37, in play
info = ytdl.extract_info(url, download=False)
File "a:\Work\piton\discord3\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 808, in extract_info
return self.__extract_info(url, ie, download, extra_info, process)
File "a:\Work\piton\discord3\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 824, in wrapper
self.report_error(compat_str(e), e.format_traceback())
File "a:\Work\piton\discord3\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 628, in report_error
self.trouble(error_message, tb)
File "a:\Work\piton\discord3\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 598, in trouble
raise DownloadError(message, exc_info)
youtube_dl.utils.DownloadError: ERROR: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "a:\Work\piton\discord3\venv\lib\site-packages\discord\ext\commands\bot.py", line 1350, in invoke
await ctx.command.invoke(ctx)
File "a:\Work\piton\discord3\venv\lib\site-packages\discord\ext\commands\core.py", line 1023, in invoke
await injected(*ctx.args, **ctx.kwargs) # type: ignore
File "a:\Work\piton\discord3\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: DownloadError: ERROR: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
Источник: Stack Overflow на русском