【问题标题】:Discord bot python: discord.errors.ClientException: ffmpeg was not foundDiscord bot python:discord.errors.ClientException:找不到ffmpeg
【发布时间】:2019-08-12 13:42:37
【问题描述】:

我正在尝试制作一个在语音频道中播放音乐的不和谐机器人。它连接到语音通道,但不播放任何内容。它还会在控制台中报错。

我在 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

【问题讨论】:

    标签: python python-3.x ffmpeg discord.py discord.py-rewrite


    【解决方案1】:

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

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

    【讨论】:

    • 如果我想在服务器上在线托管我的机器人怎么办?
    【解决方案2】:

    你可以试试这个模块:https://github.com/kkroening/ffmpeg-python

    pip install ffmpeg-python
    

    【讨论】:

      猜你喜欢
      • 2019-07-06
      • 2019-11-22
      • 2018-07-16
      • 2020-07-13
      • 2017-11-05
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 2021-04-30
      相关资源
      最近更新 更多