discord.py-命令引发异常:OpusNotLoaded [英] discord.py - Command raised an exception: OpusNotLoaded

查看:98
本文介绍了discord.py-命令引发异常:OpusNotLoaded的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当时正在做一个音乐机器人,但是我遇到了这个问题,我正在运行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上运行完美)。

I had similar problem. I don't know if it will work for you, but you can give it a try (when I tried to run it on my computer I got an error, but on Heroku it works perfect).

我将其添加到了脚本中:

import ctypes
import ctypes.util
 
print("ctypes - Find opus:")
a = ctypes.util.find_library('opus')
print(a)
 
print("Discord - Load Opus:")
b = discord.opus.load_opus(a)
print(b)
 
print("Discord - Is loaded:")
c = discord.opus.is_loaded()
print(c)

请记住将其放在与音频相关的任何内容之前(最好的选择是将其粘贴在开头)。

来源

Remember to put it before anything linked to audio (the best option is to paste it at the beginning).
Source

这篇关于discord.py-命令引发异常:OpusNotLoaded的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆