部署后 Heroku 应用程序日志出错

时间:2021-06-30 08:38:34

标签: python heroku ffmpeg discord youtube-dl

我制作了一个 discord bot 并在这个 bot 中将其部署到 Heroku 我可以正常播放 youtube 歌曲,但是在 Heroku 上部署后,当我尝试播放我的歌曲时,它会在应用程序日志中出现错误

我的代码:-

import discord,requests, sys, webbrowser, bs4
import youtube_dl
import os
from dotenv import load_dotenv
import ffmpeg
from discord.ext import *
from discord.ext import commands
from discord.ext.commands import Bot
from discord.voice_client import VoiceClient
import asyncio
@client.command(pass_context=True)                      #====================================Join
async def join(ctx):
    channel = ctx.author.voice.channel
    await channel.connect()
@client.command()                                         #==================================Play
async def play(ctx, url:str):
    song_there = os.path.isfile("song.mp3")
    try:
        if song_there:
            os.remove("song.mp3")
            player.clear()
    except PermissionError:
        await ctx.send("Wait for the current playing music end or use the 'stop' command...")
        return
    await ctx.send("Getting everything ready, playing audio soon, depends on your internet speed...")
    print("Someone wants to play music let me get that ready for them...")
    voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
    ydl_opts = {
        'format': 'bestaudio/best',
            'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }],
    }
    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        ydl.download([url])
    for file in os.listdir("./"):
        if file.endswith(".mp3"):
            os.rename(file, 'song.mp3')
    voice.play(discord.FFmpegPCMAudio("song.mp3"))
    
    voice.volume = 100

它在 localhost 上从 vscode 正常运行

但是当我在 Heroku 上部署后尝试使用它时,它给了我以下错误

2021-06-30T07:41:09.476383+00:00 app[worker.1]: The above exception was the direct cause of the following exception:
2021-06-30T07:41:09.476384+00:00 app[worker.1]: 
2021-06-30T07:41:09.476384+00:00 app[worker.1]: Traceback (most recent call last):
2021-06-30T07:41:09.476422+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 939, in invoke
2021-06-30T07:41:09.476423+00:00 app[worker.1]:     await ctx.command.invoke(ctx)
2021-06-30T07:41:09.476427+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/discord/ext/commands/core.py", line 863, in invoke
2021-06-30T07:41:09.476427+00:00 app[worker.1]:     await injected(*ctx.args, **ctx.kwargs)
2021-06-30T07:41:09.476451+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/discord/ext/commands/core.py", line 94, in wrapped
2021-06-30T07:41:09.476452+00:00 app[worker.1]:     raise CommandInvokeError(exc) from exc
2021-06-30T07:41:09.476487+00:00 app[worker.1]: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: DownloadError: ERROR: ffprobe/avprobe and ffmpeg/avconv not found. Please install one.

请帮我解决这个问题

0 个答案:

没有答案