Discord bot python: discord.errors.ClientException: ffmpeg was not found

做~自己de王妃 提交于 2021-02-16 03:58:56

问题


I'm trying to make a discord bot that plays music in a voice channel. It connects to the voice channel, but doesn't play anything. It also gives an error in the console.

I'm on Windows and I'm using the discord.py rewrite.

My code:

import discord, random, datetime, asyncio, nacl, ffmpeg

TOKEN = 'What token'

client = discord.Client()

@client.event
async def on_message(message):
if message.content.lower() == '$play':
    if message.content.lower() == '$play':
        channel = client.get_channel(547155964328149007)
        vc = await channel.connect()
        vc.play(discord.FFmpegPCMAudio('mp3.mp3'), after=lambda e: print('done', e))
        vc.is_playing()
        vc.pause()
        vc.resume()
        vc.stop()

@client.event
async def on_ready():
    print('Logged in as {0.user}'.format(client))

client.run(TOKEN)

The error:

Traceback (most recent call last):
  File "D:\Python35\lib\site-packages\discord\client.py", line 218, in _run_event
    await coro(*args, **kwargs)
  File "discord_bot.py", line 90, in on_message
    vc.play(discord.FFmpegPCMAudio('mp3.mp3'), after=lambda e: print('done', e))
  File "D:\Python35\lib\site-packages\discord\player.py", line 165, in __init__
    raise ClientException(executable + ' was not found.') from None
discord.errors.ClientException: ffmpeg was not found.

People seem to have a similar-ish issue with ffmpeg/avconv was not found in your PATH environment variable but the fix for them is to download ffmpeg from a website and put it in their PATH, but that doesn't work for me.

Further more I can only find fixes for my problem in JavaScript, while I'm coding the bot in Python 3.

Here are some links from my research:

You need to add FFmpeg to your path

A discord.js (JavaScript) fix for the same error

A fix for discord.py, NOT for discord.py REWRITE


回答1:


You can specify the FFmpeg executable directly with the argument executable:

vc = await channel.connect()
vc.play(discord.FFmpegPCMAudio(executable="C:/path/ffmpeg.exe", source="mp3.mp3"))


来源:https://stackoverflow.com/questions/55284892/discord-bot-python-discord-errors-clientexception-ffmpeg-was-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!