0

Код

from discord.ext import commands
from discord.utils import get
from youtube_dl import YoutubeDL

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

@bot.event
async def on_ready():
    print(f'{bot.user} has connected to Discord!')

@bot.command()
async def play(ctx, *, query):
    voice_channel = ctx.author.voice.channel
    if voice_channel:
        await voice_channel.connect()
        voice = get(bot.voice_clients, guild=ctx.guild)
        with YoutubeDL({'format': 'bestaudio', 'noplaylist':'True'}) as ydl:
            info = ydl.extract_info(f"ytsearch:{query}", download=False)['entries'][0]
            URL = info['formats'][0]['url']
            source = await discord.FFmpegOpusAudio.from_probe(URL)
            voice.play(source)
    else:
        await ctx.send("You are not connected to a voice channel.")

@bot.command()
async def stop(ctx):
    voice = get(bot.voice_clients, guild=ctx.guild)
    if voice.is_playing():
        voice.stop()
        await ctx.send("Stopped the music.")
    else:
        await ctx.send("No music is playing.")

bot.run('TOKEN') 

При выполнении команды !play (название музыки) происходит это:

[2023-03-03 20:23:54] [INFO    ] discord.voice_client: Connecting to voice...
[2023-03-03 20:23:54] [INFO    ] discord.voice_client: Starting voice handshake... (connection attempt 1)
[2023-03-03 20:23:55] [INFO    ] discord.voice_client: Voice handshake complete. Endpoint found frankfurt5438.discord.media
[download] Downloading playlist: phonk
[youtube:search] query "phonk": Downloading page 1
[youtube:search] playlist phonk: Downloading 1 videos
[download] Downloading video 1 of 1
[youtube] zG6NcHtMBHc: Downloading webpage
[youtube] Downloading just video zG6NcHtMBHc 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.

1 ответ 1

0

Чтобы решить данную проблему попробуйте обновить YouTube_dl

 pip install --upgrade youtube_dl

вы можете попробовать другой метод для извлечения видео

    info = await bot.loop.run_in_executor(None, lambda: ydl.extract_info(f"ytsearch:{query}", download=False))
URL = info['entries'][0]['formats'][0]['url']
2
  • У меня установлен и обновлен youtube_dl но все равно эта ошибка
    – Artem
    4 мар в 9:54
  • вы можете попробовать другой метод для извлечения видео info = await bot.loop.run_in_executor(None, lambda: ydl.extract_info(f"ytsearch:{query}", download=False)) URL = info['entries'][0]['formats'][0]['url'] 4 мар в 15:13

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.