Discord.py 属性错误:模块"键入"没有属性"_UnionGenericAlias"



我已经跟踪我的错误到这段代码,这是在一个齿轮:

@cog_ext.cog_slash(name="help")
async def help_slash(self, ctx, Command_Name=None):

await helpMethod(ctx, Command_Name)

下面是完整的错误:

Traceback (most recent call last):
File "main.py", line 102, in <module>
class bot(commands.Cog):
File "main.py", line 110, in bot
async def help_slash(self, ctx, Command_Name=None):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_slash/cog_ext.py", line 63, in wrapper
opts = manage_commands.generate_options(cmd, desc, connector)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_slash/utils/manage_commands.py", line 313, in generate_options
SlashCommandOptionType.from_type(param.annotation) or SlashCommandOptionType.STRING
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_slash/model.py", line 488, in from_type
and isinstance(t, typing._UnionGenericAlias)  # noqa
AttributeError: module 'typing' has no attribute '_UnionGenericAlias'

我的研究表明这可能是Python本身的错误。如果是这样,有没有办法规避这个问题?我已经测试了helpMethod:这个错误来自斜杠命令的声明。

感谢您的阅读。

查看Python 3.8类型库代码,可以看到_UnionGenericAlias没有定义。然而,在Python 3.9中,它是被定义的。所以解决方案是你必须升级你的Python版本。

最新更新