首页 > 解决方案 > Discord.py: has_permissons() 不工作——错误不是 MissingPermissions 的一个实例

问题描述

我一直在尝试实现一个不和谐命令,如果用户具有manage_roles权限 types !add_country UAE,机器人会将 args(即阿联酋)附加到文本文件中。一切似乎都在工作,除了错误处理程序以防manage_roles缺少权限。

from discord.ext import commands

from discord.ext.commands import has_permissions, MissingPermissions


@bot.command(name = "add_country", pass_context=True)
@has_permissions(manage_roles=True)  
async def add_country(ctx, arg):
    with open('countries.txt', 'a') as f:
        f.write(f"""\n{arg}""")
    await ctx.channel.send(f"""Added {arg} to the list of countries""")

@add_country.error
async def add_country_error(error, ctx):
    if isinstance(error, MissingPermissions):
        await ctx.send("You don't have permission to do that!")

    else:
        print("Not an instance")

当没有权限的用户发送命令时,输出Not an instance会被打印出来。所以我可以清楚地得出结论,isinstance() 函数有问题。如果有人可以帮助我,那就太好了。

提前致谢!

标签: pythondiscorddiscord.py

解决方案


推荐阅读