-1

I'm trying to get the discord bot to play the music I input with a link (in the app command) but it always responds with unable to extract initial data which I don't know the meaning of. I've tried many different videos and I have had the same error with youtube dl (I thought switching would fix that).

Here's the console output:

[youtube] Extracting URL: https://www.youtube.com/watch?v=QHRzcG9z5Zg
[youtube] QHRzcG9z5Zg: Downloading webpage
[youtube] QHRzcG9z5Zg: Downloading ios player API JSON
WARNING: [youtube] unable to extract initial player response; please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
[youtube] QHRzcG9z5Zg: Downloading android player API JSON
[youtube] QHRzcG9z5Zg: Downloading iframe API JS
[youtube] QHRzcG9z5Zg: Downloading player c153b631
[youtube] QHRzcG9z5Zg: Downloading web player API JSON
[youtube] QHRzcG9z5Zg: Downloading m3u8 information
WARNING: [youtube] unable to extract yt initial data; please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
WARNING: [youtube] Incomplete data received in embedded initial data; re-fetching using API.
[youtube] QHRzcG9z5Zg: Downloading initial data API JSON
Task exception was never retrieved
future: <Task finished name='CommandTree-invoker' coro=<CommandTree._from_interaction.<locals>.wrapper() done, defined at C:\Users\orthe\PycharmProjects\Discord_Bot\venv\Lib\site-packages\discord\app_commands\tree.py:1087> exception=NotFound('404 Not Found (error code: 10062): Unknown interaction')>
Traceback (most recent call last):
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\venv\Lib\site-packages\discord\app_commands\commands.py", line 827, in _do_call
    return await self._callback(self.binding, interaction, **params)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\Cogs\music.py", line 53, in music
    voice_client.play(discord.FFmpegPCMAudio(url2))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\venv\Lib\site-packages\discord\player.py", line 290, in __init__
    super().__init__(source, executable=executable, args=args, **subprocess_kwargs)
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\venv\Lib\site-packages\discord\player.py", line 166, in __init__
    self._process = self._spawn_process(args, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\venv\Lib\site-packages\discord\player.py", line 183, in _spawn_process
    raise ClientException(executable + ' was not found.') from None
discord.errors.ClientException: ffmpeg was not found.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\venv\Lib\site-packages\discord\app_commands\tree.py", line 1248, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\venv\Lib\site-packages\discord\app_commands\commands.py", line 853, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\venv\Lib\site-packages\discord\app_commands\commands.py", line 846, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'music' raised an exception: ClientException: ffmpeg was not found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\venv\Lib\site-packages\discord\app_commands\tree.py", line 1089, in wrapper
    await self._call(interaction)
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\venv\Lib\site-packages\discord\app_commands\tree.py", line 1251, in _call
    await command._invoke_error_handlers(interaction, e)
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\venv\Lib\site-packages\discord\app_commands\commands.py", line 770, in _invoke_error_handlers
    await self.on_error(self.binding, interaction, error)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\Cogs\music.py", line 58, in on_music_error
    await interaction.response.send_message(str(error), ephemeral=True)
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\venv\Lib\site-packages\discord\interactions.py", line 801, in send_message
    await adapter.create_interaction_response(
  File "C:\Users\orthe\PycharmProjects\Discord_Bot\venv\Lib\site-packages\discord\webhook\async_.py", line 219, in request
    raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

This is the code I am using:

from discord.ext import commands
from discord import app_commands
import discord
import yt_dlp



class music(commands.Cog):
    def __init__(self, bot):
        self.bot = bot


    @app_commands.command(name="music", description="plays music")
    async def music(self, interaction: discord.Interaction, url: str):
        # Join the voice channel of the command invoker
        channel = interaction.user.voice.channel
        voice_client = await channel.connect()

        # Download audio from YouTube using youtube-dl
        ydl_opts = {
            'format': 'bestaudio/best',
            'postprocessors': [{
                'key': 'FFmpegExtractAudio',
                'preferredcodec': 'mp3',
                'preferredquality': '192',
            }]}

        with yt_dlp.YoutubeDL(ydl_opts) as ydl:
            info = ydl.extract_info(url, download=False)
            url2 = info['formats'][0]['url']

        # Play audio
        voice_client.play(discord.FFmpegPCMAudio(url2))


    @music.error
    async def on_music_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError):
        await interaction.response.send_message(str(error), ephemeral=True)


async def setup(bot):
    await bot.add_cog(music(bot))
Gugu72
  • 2,052
  • 13
  • 35
slin
  • 1
  • 1

0 Answers0