Для начала, я пытаюсь создать бота, который воспроизводит звук из Ютуб видео. При вызове команды и указания ссылки или названия видео, вылезает такая ошибка, при этом код работает, так как в чате высвечивается "Не удалось загрузить песню. Неправильный формат, попробуйте другое ключевое слово", как я сам и указал, что при неправильном использовании команды должно высвечиваться это сообщение, но я делаю все правильно, так что я в замешательстве.
Бот MFMF_bot#0269 запустился и может начать работать
[download] Downloading playlist: https://www.youtube.com/watch?v=eiu7DGltccM
[youtube:search] query "https://www.youtube.com/watch?v=eiu7DGltccM": Downloading page 1
[youtube:search] playlist https://www.youtube.com/watch?v=eiu7DGltccM:
Downloading 1 videos
[download] Downloading video 1 of 1
[youtube] eiu7DGltccM: Downloading webpage
[youtube] Downloading just video eiu7DGltccM because of --no-playlist
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.
Сверху то что появляется у меня в терминале при использовании команды, а снизу сам код
import disnake
from disnake.ext import commands
from youtube_dl import YoutubeDL
class music_cog(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.is_playing = False
self.is_paused = False
self.music_queue = []
self.YDL_OPTIONS = {"format": "bestaudio", "noplaylist": "True"}
self.FFMPEG_OPTIONS = {"before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5", "options": "-vn"}
self.vc = None
def search_yt(self, item):
with YoutubeDL(self.YDL_OPTIONS) as ydl:
try:
info = ydl.extract_info("ytsearch:%s" % item, download=False)["entries"][0]
except Exception:
return False
return {"source": info["formats"][0]["url"], "title": info["title"]}
def play_next(self):
if len(self.music_queue) > 0:
self.is_playing=True
m_url=self.music_queue[0][0]["source"]
self.music_queue.pop(0)
self.vc.play(disnake.FFmpegPCMAudio(m_url, **self.FFMPEG_OPTIONS), after=lambda e: self.play_next())
else:
self.is_playing=False
async def play_music(self, ctx):
if len(self.music_queue) > 0:
self.is_playing=True
m_url=self.music_queue[0][0]["source"]
if self.vc == None or not self.vc.is_connect():
self.vc = await self.music_queue[0][1].connect()
if self.vc == None:
await ctx.send("Я хз куда подключаться")
return
else:
await self.vc.move_to(self.music_queue[0][1])
self.music_queue.pop(0)
self.vc.play(disnake.FFmpegPCMAudio(m_url, **self.FFMPEG_OPTIONS), after=lambda e: self.play_next())
else:
self.is_playing=False
@commands.command(name="play", aliases=["p", "playing"], help="Воспроизводит выбранную музыку из ютуба")
async def playm(self, ctx, *args):
query=" ".join(args)
voice_channel=ctx.author.voice.channel
if voice_channel is None:
await ctx.send("Подключись к голосовому каналу")
elif self.is_paused:
self.vc.resume()
else:
song=self.search_yt(query)
if type(song) == type(True):
await ctx.send("Не удалось загрузить песню. Неправильный формат, попробуйте другое ключевое слово")
else:
await ctx.send("Песня добавлена в очередь")
self.music_queue.append([song, voice_channel])
if self.is_playing == False:
await self.play_music(ctx)
@commands.command(name="pause", help="Ставит на паузу воспроизводимую музыку")
async def pausem(self, ctx, *args):
if self.is_playing:
self.is_playing = False
self.is_paused = True
self.vc.pause()
elif self.is_paused:
self.is_playing = True
self.is_paused = False
self.vc.resume()
@commands.command(name="resume", aliases=["r"], help="Возобновляет воспроизведение музыку поставленной на паузу")
async def resumem(self, ctx, *args):
if self.is_paused:
self.is_playing = True
self.is_paused = False
self.vc.resume()
@commands.command(name="skip", aliases=["s"], help="Скипает песню воспроизводя следующую по списку")
async def skipm(self, ctx, *args):
if self.vc != None and self.vc:
self.vc.stop()
await self.play_music(ctx)
@commands.command(name="queue", aliases=["q"], help="Показывает в чате какие песни в очереди")
async def queuem(self, ctx):
retval = ""
for i in range(0, len(self.music_queue)):
if i > 4: break
retval += self.music_queue[i][0]["title"] + "\n"
if retval != "":
await ctx.send(retval)
else:
await ctx.send("Музыки в очереди больше нету")
@commands.command(name="clear", aliases=["c", "bin"], help="Очищащет весь список воспроизводимой музыки")
async def clearm(self, ctx, *args):
if self.vc != None and self.is_playing:
self.vc.stop()
self.music_queue = []
await ctx.send("Плейлист очищен")
@commands.command(name="leave", aliases=["disconnect", "l", "d"], help="Бот уходит из голосового чата")
async def leavem(self, ctx):
self.is_playing = False
self.is_paused = False
await self.vc.disconnect()