【问题标题】:My heroku music bot works fine if i launch it through my pc yet when i run it through heroku it doesn't work如果我通过我的电脑启动它,我的 heroku 音乐机器人工作正常,但是当我通过 heroku 运行它时它不起作用
【发布时间】:2020-06-18 14:11:11
【问题描述】:

我安装了 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 上检查您的错误跟踪。
  • 我似乎没有任何错误,得到重命名的文件然后什么都没有gyazo.com/b4110a13b393721c0b2a743a8fb3b4aa
  • 因为记录了“重命名文件”但不是最后一个 print(playing) 这告诉我上面的 5 行代码出了点问题。尝试在它们之间添加打印语句,看看哪个没有被记录。这将查明错误
  • 好的,所以我测试了一下,这里似乎是这条线voice.play(discord.FFmpegPCMAudio("song.mp3"), after=lambda e: print(f"{name} has finished playing"))我仍然不确定为什么!
  • 太棒了。看看下面的答案

标签: python heroku ffmpeg bots discord


【解决方案1】:

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

来源:

https://elements.heroku.com/buildpacks/jonathanong/heroku-buildpack-ffmpeg-latest

【讨论】:

  • 我已经将 FFmpeg 添加为构建包!抱歉回复晚了
  • 嗯...这很奇怪。你可以试试this吗?
  • 您到底想让我尝试什么?
  • 所有解决方案。
  • 很抱歉,我很无奈。您可以尝试将其托管在其他云提供商上。
猜你喜欢
  • 2020-10-09
  • 1970-01-01
  • 2022-11-06
  • 2016-02-05
  • 1970-01-01
  • 2015-12-12
  • 2021-08-02
  • 1970-01-01
  • 2021-08-11
相关资源
最近更新 更多