gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:38:06 33 4
gpt4 key购买 nike

我正在尝试制作一个在语音 channel 中播放音乐的 discord 机器人。它连接到语音 channel ,但不播放任何内容。它还会在控制台中给出错误。

我在 Windows 上,我正在使用 discord.py 重写。

我的代码:

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)

错误:

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.

人们似乎对 ffmpeg/avconv was not found in your PATH environment variable 有类似的问题,但解决方法是从网站下载 ffmpeg 并将其放入他们的 PATH,但这对我不起作用。

此外,我只能在 JavaScript 中找到解决我的问题的方法,而我正在用 Python 3 编写机器人程序。

以下是我研究的一些链接:

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

最佳答案

您可以直接使用参数executable指定FFmpeg可执行文件:

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

关于python - Discord bot python : discord. errors.ClientException: ffmpeg was not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55284892/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com