问题
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