Python Discord Bot FFmpeg Path Issue

I’m having trouble with my Discord bot that uses Python 3.5.2 and the discord module. The bot is supposed to play YouTube videos but it’s not working. I’ve installed FFmpeg and added it to my PATH variable on my Mac (OSX El Capitan), but I’m still getting an error.

Here’s a snippet of my code:

user_voice = message.author.voice_channel
bot_voice = await bot.connect_to_voice(user_voice)
yt_player = await bot_voice.setup_youtube_stream(video_url)
yt_player.begin()

The error message says FFmpeg can’t be found:

Error: FFmpeg not found in PATH
Details: subprocess.FileNotFoundError
Message: No such file or directory: 'ffmpeg'

I’ve double-checked my PATH and FFmpeg is there. Any ideas on what might be causing this or how to fix it? I’m pretty stumped.

As someone who’s wrestled with similar FFmpeg issues, I can relate to your frustration. One thing that worked for me was using the absolute path to FFmpeg in my script. Instead of relying on PATH, you could try something like this:

import discord
import subprocess

ffmpeg_path = ‘/usr/local/bin/ffmpeg’ # Adjust this to your actual FFmpeg location

In your bot’s setup

bot = discord.Client(ffmpeg=ffmpeg_path)

This bypasses PATH issues entirely. Also, make sure you’re using a recent version of discord.py - older versions can be finicky with FFmpeg. If you’re still stuck, you might want to consider using a different audio library like PyNaCl, which some find more reliable for Discord bots. Hope this helps!

Have you tried explicitly setting the FFmpeg path in your Python script? Sometimes the system PATH isn’t correctly recognized by Python, especially in virtual environments. You could add this at the beginning of your script:

import os
os.environ[‘PATH’] += ‘:/usr/local/bin’ # Adjust this path as needed

This ensures Python knows where to find FFmpeg. Also, double-check that you’re using a compatible version of discord.py with your Python 3.5.2. Older versions might have issues with FFmpeg detection. If all else fails, consider updating your Python and discord.py to more recent versions, as they often have improved compatibility and error handling for these types of issues.

hey stella, i had similar issue. try running ur script with sudo or as admin. sometimes it’s a permissions thing. also, check if ffmpeg is in /usr/local/bin. if not, try adding the correct path to ur script. good luck!