python - "FFmpeg was not found, spotdl can' t continue”,即使它是使用 sudo apt-get install spotdl 安装的 + 如果从终端运行它也可以工作

标签 python ffmpeg discord.py

@bot.command()
async def getsong(ctx, *, songname):
    "get song in mp3 from song name"
    os.popen(f'spotdl {songname} -f "/home/pi/discordbot/output/{songname}.mp3"')
    await ctx.send(file=discord.File(fr'/home/pi/discordbot/output/{songname}.mp3'))
使用 sudo-apt get 安装的 ffmpeg。如果从终端运行则有效
怎么修?
我自己弄清楚了。
工作代码,如果它有利于任何人:
@bot.command()
async def getsong(ctx, *, songname):
    "get song in mp3 from song name"
    subprocess.Popen(f'spotdl -o "/home/pi/discordbot/output" --ffmpeg "/usr/bin/ffmpeg" {songname} --path-template "{songname}.mp3"', shell=True)
    await ctx.send(file=discord.File(fr'/home/pi/discordbot/output/{songname}.mp3'))

最佳答案

尝试使用 subprocess.check_output来自子流程,例如

@bot.command()
async def getsong(ctx, *, songname):
    # get song in mp3 from song name :D
    subprocess.check_output(f'spotdl {songname} -f "/home/pi/discordbot/output/{songname}.mp3"', shell=True)
    await ctx.send(file=discord.File(f'/home/pi/discordbot/output/{songname}.mp3'))

关于python - "FFmpeg was not found, spotdl can' t continue”,即使它是使用 sudo apt-get install spotdl 安装的 + 如果从终端运行它也可以工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72706502/

相关文章:

python - 在 python 中并行读取多个大小为 10GB 的大型 csv 文件

python - 将 html 保存到文件中,以便以后使用 Beautiful Soup 使用

python - 从具有任意轴数的数组中读取具有给定索引的元素

python - Flask post/redirect/get 模式无法从错误中恢复

c# - ffmpeg 波形音频和 avi 视频格式合并

video - ffmpeg,如何在结束前0.5秒提取单帧?

php - Google Speech API - 有没有办法确定音频是否有人声?

python - CommandOnCooldown 错误处理程序未捕获错误!已经测试了一切

python - Discord.py - 以不同的名称或用户发送消息

python - 无法将机器人连接到不和谐