Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的heroku音乐机器人工作正常,如果我通过pc启动它,但当我通过heroku运行它时,它不会';行不通_Python_Heroku_Ffmpeg_Bots_Discord - Fatal编程技术网

Python 我的heroku音乐机器人工作正常,如果我通过pc启动它,但当我通过heroku运行它时,它不会';行不通

Python 我的heroku音乐机器人工作正常,如果我通过pc启动它,但当我通过heroku运行它时,它不会';行不通,python,heroku,ffmpeg,bots,discord,Python,Heroku,Ffmpeg,Bots,Discord,我已经安装了ffmpeg,youtube dl,我已经安装了所有的要求,它下载了歌曲并重命名了它,但是什么都没有发生 @client.command() async def play(ctx, *url: str): song_there = os.path.isfile("song.mp3") try: if song_there: os.remove("song.mp3") print("Removed old

我已经安装了ffmpeg,youtube dl,我已经安装了所有的要求,它下载了歌曲并重命名了它,但是什么都没有发生

@client.command()
async def play(ctx, *url: str):
    song_there = os.path.isfile("song.mp3")
    try:
        if song_there:
            os.remove("song.mp3")
            print("Removed old song file")
    except PermissionError:
        print("Trying to delete song file, but it's being played")
        await ctx.send("ERROR: Music playing")
        return

    await ctx.send("Getting everything ready now")

    voice =  get(client.voice_clients,  guild=ctx.guild)

    ydl_opts = {
        'format': 'bestaudio/best',
        'quiet': True,
        'outtmpl':"./song.mp3",
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }],
    }

    song_search = " ".join(url)

    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        print("Downloading audio now\n")
        ydl.download([f"ytsearch1:{song_search}"])

    for file in os.listdir("./"):
        if file.endswith(".mp3"):
            name = file
            print(f"Renamed File: {file}\n")
            os.rename(file, "song.mp3")

    voice.play(discord.FFmpegPCMAudio("song.mp3"), after=lambda e: print(f"{name} has finished playing"))
    voice.source = discord.PCMVolumeTransformer(voice.source)
    voice.source.volume = 0.10

    nname = name.rsplit("-", 2)
    await ctx.send(f"Currently playing: {nname}")
    print("playing\n")

Heroku支持ffmpeg作为应用程序的构建包。只需在
https://dashboard.heroku.com/apps/[app name]/settings
并向下滚动到Buildpacks,您应该在其中添加
https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git
将其删除

或者,您也可以运行CLI命令:

$ heroku buildpacks:add https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git
资料来源:

很难说问题出在哪里,请尝试检查heroku上的错误跟踪。我似乎根本没有收到任何错误,访问重命名的文件,然后什么都没有,因为“重命名的文件”已被记录,但不是上次的
打印(播放)
这告诉我,它正上方的5行代码出现了问题。尝试在它们之间添加print语句,看看哪个语句没有被记录下来。这将精确定位错误OK,所以我测试了一点,这里似乎是这一行
voice.play(discord.FFmpegPCMAudio(“song.mp3”),after=lambda e:print(f“{name}已完成播放”)
我仍然不确定为什么!伟大的请参见下面的答案,我们已经将FFmpeg添加为构建包了!很抱歉回复晚了嗯。。。真奇怪。你能试试吗?你到底想让我试试什么?所有的解决方案都有。很抱歉,在这种情况下,我无能为力。您可以尝试在其他云提供商上托管它。