Search code examples
python-3.xdiscord.pyyoutube-dl

Discord Bot Music (discord.py) - ERROR: ffprobe/avprobe and ffmpeg/avconv not found. Please install one. How to fix on Pycharm


Salutations. I am trying to create a music bot on discord and when I try to download it warns me of the error. Since I use pycharm many solutions are not for me or do not work, I don't know how to do it. Here the code:

@client.command()
async def play(ctx, url : str):
    song_there = os.path.isfile("song.mp3")
    try:
        if song_there:
            os.remove("song.mp3")
    except PermissionError:
        await ctx.send("Wait for the current playing music to end or use the 'stop' command")
        return

    voiceChannel = discord.utils.get(ctx.guild.voice_channels, id=638017907791626250)
    await voiceChannel.connect()
    voice = discord.utils.get(client.voice_clients, guild=ctx.guild)

    ydl_opts = {
        'format': 'bestaudio/best',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }],
    }
    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        ydl.download([url])
    for file in os.listdir("./"):
        if file.endswith(".mp3"):
            os.rename(file, "song.mp3")
    voice.play(discord.FFmpegPCMAudio("song.mp3"))

Solution

  • I solved: just download the build (windows link: https: //www.gyan.dev/ffmpeg/builds/ffmpeg-git-full.7z) and extract ffmpeg.exe, ffplay.exe and ffprobe.exe and put them in the scripts folder inside our project folder