ytdl-org / youtube-dl

Command-line program to download videos from YouTube.com and other video sites
http://ytdl-org.github.io/youtube-dl/
The Unlicense
132.74k stars 10.07k forks source link

Python discord bot cant install music, i am making a music bot for discord and bot and gives error when i using !play <link> #31883

Closed noxygalaxy closed 1 year ago

noxygalaxy commented 1 year ago

there is code:

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

intents = discord.Intents.all()

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

@bot.command(pass_context=True) async def play(ctx, url): if not ctx.author.voice: await ctx.send('You are not connected to a voice channel') return else: channel = ctx.author.voice.channel voice = get(bot.voice_clients, guild=ctx.guild) if voice and voice.is_connected(): await voice.move_to(channel) else: voice = await channel.connect()

ydl_opts = {'format': 'bestaudio', 'noplaylist':'True'}
with YoutubeDL(ydl_opts) as ydl:
    info = ydl.extract_info(url, download=False)
    URL = info['url']
    source = await discord.FFmpegOpusAudio.from_probe(URL)
    voice.play(source)
await ctx.send(f'Bot is playing {url}')

@bot.command(pass_context=True) async def stop(ctx): voice = get(bot.voice_clients, guild=ctx.guild) if voice and voice.is_playing(): voice.stop() await ctx.send('bot stopped')

bot.run('MY TOKEN HERE')

Error

[2023-03-19 17:35:07] [INFO ] discord.client: logging in using static token [2023-03-19 17:35:08] [INFO ] discord.gateway: Shard ID None has connected to Gateway (Session ID: 3da680acbcc29b619910da17abab2e7f). [2023-03-19 17:35:12] [INFO ] discord.voice_client: Connecting to voice... [2023-03-19 17:35:12] [INFO ] discord.voice_client: Starting voice handshake... (connection attempt 1) [2023-03-19 17:35:12] [INFO ] discord.voice_client: Voice handshake complete. Endpoint found bucharest2980.discord.media [youtube] grd-K33tOSM: Downloading webpage [youtube] Downloading just video grd-K33tOSM 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. [2023-03-19 17:35:14] [ERROR ] discord.ext.commands.bot: Ignoring exception in command play Traceback (most recent call last): File "C:\Users\vimew\AppData\Local\Programs\Python\Python311\Lib\site-packages\youtube_dl\YoutubeDL.py", line 815, in wrapper return func(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\vimew\AppData\Local\Programs\Python\Python311\Lib\site-packages\youtube_dl\YoutubeDL.py", line 836, in __extract_info ie_result = ie.extract(url) ^^^^^^^^^^^^^^^ File "C:\Users\vimew\AppData\Local\Programs\Python\Python311\Lib\site-packages\youtube_dl\extractor\common.py", line 534, in extract ie_result = self._real_extract(url) ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\vimew\AppData\Local\Programs\Python\Python311\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 "C:\Users\vimew\AppData\Local\Programs\Python\Python311\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 "C:\Users\vimew\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\core.py", line 229, in wrapped ret = await coro(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Windows\00music-bot\main.py", line 26, in play info = ydl.extract_info(url, download=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\vimew\AppData\Local\Programs\Python\Python311\Lib\site-packages\youtube_dl\YoutubeDL.py", line 808, in extract_info return self.__extract_info(url, ie, download, extra_info, process) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\vimew\AppData\Local\Programs\Python\Python311\Lib\site-packages\youtube_dl\YoutubeDL.py", line 824, in wrapper self.report_error(compat_str(e), e.format_traceback()) File "C:\Users\vimew\AppData\Local\Programs\Python\Python311\Lib\site-packages\youtube_dl\YoutubeDL.py", line 628, in report_error self.trouble(error_message, tb) File "C:\Users\vimew\AppData\Local\Programs\Python\Python311\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 "C:\Users\vimew\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\bot.py", line 1350, in invoke await ctx.command.invoke(ctx) File "C:\Users\vimew\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\ext\commands\core.py", line 1023, in invoke await injected(*ctx.args, **ctx.kwargs) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\vimew\AppData\Local\Programs\Python\Python311\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.

dirkf commented 1 year ago

30839 !