command.MissingRole(missing_role)错误处理

时间:2020-08-05 16:03:50

标签: python discord discord.py chatbot python-3.8

严重问题怎么解决?

import matplotlib.pyplot as plt
import seaborn as sns; sns.set(style="ticks", color_codes=True)
iris = sns.load_dataset("iris")

pg1 = sns.pairplot(iris[1::2], hue="species", corner=True)
pg2 = sns.pairplot(iris[::2], hue="species", corner=False, diag_kind=None))

# remove lower triangle and diagonal from figure 2
for ax in pg2.fig.get_axes():
    if ax.get_geometry()[2] in [1,5,6,9,10,11,13,14,15,16]:
        ax.remove()

# add all axes from figure 1 (lower triangle and diagonal) to figure 2
for ax in pg1.fig.get_axes():
    ax.figure = pg2.fig # in the next step we can only add axes from the same figure
    pg2.fig.add_axes(ax)

# close figure 1 which is not needed anymore    
plt.close(pg1.fig)

给出错误:

command.MissingRole(missing_role)错误处理

1 个答案:

答案 0 :(得分:0)

isinstance仅可以告诉error是否是MissingRole对象,如果它代表特定的缺少角色,则不能。您应该将其分开作为自己的支票

@say.error
async def say_error(ctx, error):
    if isinstance(error, commands.MissingRole):
        if error.missing_role.id == 730356075689410570:
            await ctx.send(f'`You dont have {error.missing_role} role..')
        else:
            await ctx.send("You are missing some other role")
    else:
        raise error  # if we can't handle the error, bubble it back up