问题描述
我正在制作一个音乐机器人,但我遇到了这个问题,我正在运行 python 3.6.8 并且它托管在 heroku 上
i was making an music bot but i had it having this problem, im running python 3.6.8 and its hosted on heroku
我听说我需要使用 discord.opus.loadopus 或类似的东西,但我不知道如何将它添加到我的代码以及在哪里,请帮助
i've heard i need to use discord.opus.loadopus or something like that but i dont know how to add it to my code and where, please help
这是我的代码
import discord import asyncio from discord.ext import commands client = commands.bot(command_prefix='!') songs = asyncio.queue() play_next_song = asyncio.event() @client.event async def on_ready(): print('client ready') async def audio_player_task(): while true: play_next_song.clear() current = await songs.get() current.start() await play_next_song.wait() def toggle_next(): client.loop.call_soon_threadsafe(play_next_song.set) @client.command(pass_context=true) async def play(ctx, url): if not client.is_voice_connected(ctx.message.server): voice = await client.join_voice_channel(ctx.message.author.voice_channel) else: voice = client.voice_client_in(ctx.message.server) player = await voice.create_ytdl_player(url, after=toggle_next) await songs.put(player) client.loop.create_task(audio_player_task()) client.run('token')
我有这个错误:
ignoring exception in command play traceback (most recent call last): file "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 50, in wrapped ret = yield from coro(*args, **kwargs) file "draco.py", line 30, in play voice = await client.join_voice_channel(ctx.message.author.voice_channel) file "/app/.heroku/python/lib/python3.6/site-packages/discord/client.py", line 3209, in join_voice_channel voice = voiceclient(**kwargs) file "/app/.heroku/python/lib/python3.6/site-packages/discord/voice_client.py", line 230, in __init__ self.encoder = opus.encoder(48000, 2) file "/app/.heroku/python/lib/python3.6/site-packages/discord/opus.py", line 197, in __init__ raise opusnotloaded() discord.opus.opusnotloaded the above exception was the direct cause of the following exception: traceback (most recent call last): file "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 846, in process_commands yield from command.invoke(ctx) file "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 374, in invoke yield from injected(*ctx.args, **ctx.kwargs) file "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 54, in wrapped raise commandinvokeerror(e) from e discord.ext.commands.errors.commandinvokeerror: command raised an exception: opusnotloaded:
推荐答案
你不需要在你的代码中添加任何东西,试着把它添加到你在 heroku 上的 buildpacks 中:
you don't need to add anything to your code, try adding this to your buildpacks on heroku:
http://www.51sjk.com/upload/articles/1/0/342/342073_20230201092318005.git