首页 > 解决方案 > discord.py 播放命令在使用 heroku 时出现 opus 问题

问题描述

所以我的机器人中有一个播放命令

@client.command()
    async def play(ctx, url):
    YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist':'True'}
    FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
    voice = discord.utils.get(client.voice_clients, guild=ctx.guild)

    if not voice.is_playing():
        with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
            info = ydl.extract_info(url, download=False)
        URL = info['formats'][0]['url']
        voice.play(discord.FFmpegPCMAudio(URL, **FFMPEG_OPTIONS))
        voice.is_playing()
    else:
        await ctx.send("Already playing song")
        return

discord.opus.load_opus("opus")开头的一行。当我尝试运行命令时出现此错误OSError: opus: cannot read file data: Is a directory

PS我正在使用 Heroku 24/7 运行机器人

标签: pythondiscord.py

解决方案


discord.opus.load_opus("opus")不是必需的;您可以安全地删除它。

https://github.com/xrisk/heroku-opus.git buildpack 已经将opus 添加到库路径中。无需进一步配置:)


推荐阅读