Python Discord.py错误;即使在环境变量中安装和配置ffmpeg,也找不到它

Python Discord.py错误;即使在环境变量中安装和配置ffmpeg,也找不到它,python,ffmpeg,discord.py,youtube-dl,Python,Ffmpeg,Discord.py,Youtube Dl,因此,我正在尝试将音乐机器人功能集成到我的Discord机器人中,我将只链接我怀疑有问题的代码 import discord from discord.ext import commands import praw import random import os import json import ffmpeg import youtube_dl # music command @client.command(pass_context=true) async def play(ctx, ur

因此,我正在尝试将音乐机器人功能集成到我的Discord机器人中,我将只链接我怀疑有问题的代码

import discord
from discord.ext import commands
import praw
import random
import os
import json
import ffmpeg
import youtube_dl

# music command
@client.command(pass_context=true)
async def play(ctx, url):
    server = ctx.message.server
    voice_client = client.voice_client_in(server)
    player = await voice.client.create_ytdl_player(url)
    players[server.id] = player
    player.start()
这里是错误

Traceback (most recent call last):
  File "C:\Users\Trayambak\Desktop\Akihiko\bot.py", line 8, in <module>
    import ffmpeg
ModuleNotFoundError: No module named 'ffmpeg'
[Finished in 52.353s]
回溯(最近一次呼叫最后一次):
文件“C:\Users\Trayambak\Desktop\Akihiko\bot.py”,第8行,在
导入ffmpeg
ModuleNotFoundError:没有名为“ffmpeg”的模块
[以52.353s完成]

首先,我不知道名为
ffmpeg
的模块。也许你已经创造了你自己的,但从我在你的信息中得到的情况并非如此

FFmpeg是一个基于大量C库构建的命令行工具。它不是作为Python包在本机上提供的。我知道在Python中使用它的两种方法:

  • 您可以在运行代码的计算机上安装FFmpeg,并运行本机FFmpeg命令。(本节中的信息)

  • 其他选项,使用
    ffmpeg-python
    (链接到和)。它是一个python绑定库,在python函数和FFmpeg函数/命令之间创建链接

每种方法都有其优缺点。但我会总结如下: 如果您想构建一个简单的基于FFmpeg的工具,而不需要任何关键用途,那么就使用Python绑定,这是最简单的imo。如果您想在短时间内将FFmpeg用于商业用途,请花点时间了解它的实际工作原理并使用命令行

  • 您不必导入FFmpeg
  • 服务器现在更改为
  • FFmpeg和youtube_dl发生了很大变化,因此您应该检查我发布的完整音乐机器人的代码,并将其与您的代码进行比较
  • 可选的、有用的功能 如果需要,您可以在歌曲/音乐停止播放后使您的机器人离开语音频道。将此添加到代码末尾(在client.run(Token)之前!!)

    如何使用它
    只需写下:!!播放#请记住您必须粘贴链接

    始终将问题中的完整错误消息(从单词“Traceback”开始)作为文本(而不是屏幕截图)放置。还有其他有用的信息。
    import discord
    
    import youtube_dl
    
    from discord.ext import commands
    
    Token = "your token here"           
    client = commands.Bot(command_prefix = "!!") #you can change your commands prefix here
    
    ydl_opts = {
        'format': 'bestaudio/best',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }],
    }   
    
    def endSong(guild, path):
        os.remove(path)                                   
    
    @client.command(pass_context=True)
    async def play(ctx, url):
        if not ctx.message.author.voice:
            await ctx.send('you are not connected to a voice channel')
            return
    
        else:
            channel = ctx.message.author.voice.channel
    
        voice_client = await channel.connect()
    
        guild = ctx.message.guild
    
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            file = ydl.extract_info(url, download=True)
            path = str(file['title']) + "-" + str(file['id'] + ".mp3")
    
        voice_client.play(discord.FFmpegPCMAudio(path), after=lambda x: endSong(guild, path))
        voice_client.source = discord.PCMVolumeTransformer(voice_client.source, 1)
    
        await ctx.send(f'**Music: **{url}')
    
    client.run(Token)
    
    while voice_client.is_playing():
            await asyncio.sleep(1)
        else:
            await voice_client.disconnect()
            print("Disconnected")