python - 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() 函数有问题。如果有人可以帮助我,那就太好了。
提前致谢!
解决方案
推荐阅读
- asterisk-ari - 没有接听电话时会触发哪个事件?
- c++ - 对可执行文件库加载的操作
- autodesk - DXF文件块中polyLines顶点和点之间的关系是什么?
- c - K&R 练习 6-1 在某些情况下 getword 函数无法读取 EOF
- python - 使用硒找不到登录按钮
- r - 为什么我不能用 R 3.6.1 安装中介包?
- javascript - 如何通过 NodeJS 连接远程数据库
- api - 如何使用 Gmail API(Chrome 扩展程序)通过 URL 添加图片
- node.js - 如何从父级生成单个工作实例被多次生成?
- git - 如何使用 .gitattributes 为已删除的文件指定 git 合并“我们的”策略?