Python Discord.py错误;即使在环境变量中安装和配置ffmpeg,也找不到它
因此,我正在尝试将音乐机器人功能集成到我的Discord机器人中,我将只链接我怀疑有问题的代码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
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命令。(本节中的信息)
- 其他选项,使用
(链接到和)。它是一个python绑定库,在python函数和FFmpeg函数/命令之间创建链接ffmpeg-python
只需写下:!!播放#请记住您必须粘贴链接始终将问题中的完整错误消息(从单词“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")