python - 我在使用不和谐机器人修改 json 文件时遇到了一些问题。如何解决这个问题?
问题描述
如果用户有权禁止成员,我希望机器人使此命令可操作,但是当我运行代码时,由于下面代码中的这一行@commands.has_permissions(ban_member=True)
是我的代码中的第 42行,我得到了错误
如果我删除@commands.has_permissions(ban_member=True)
它正在工作,但任何人都可以修改我不想发生的 json 文件。
如何修复此错误?
def write_json(data,filename="blacklistedWords.json"):
with open(filename,"w") as f:
json.dump(data,f,indent=4)
@bot.command(aliases=['awb'])
@commands.has_permissions(ban_member=True)
async def addtoblacklist(ctx,*,word):
with open("blacklistedWords.json") as json_file:
data = json.load(json_file)
temp = data["blacklistedWords"]
temp.append(word)
write_json(data)
Traceback (most recent call last):
File "C:\Users\ACER\Desktop\Json read write\botRead.py", line 42, in <module>
@commands.has_permissions(ban_member=True)
File "C:\Users\ACER\AppData\Roaming\Python\Python39\site-packages\discord\ext\commands\core.py", line 1779, in has_permissions
raise TypeError('Invalid permission(s): %s' % (', '.join(invalid)))
TypeError: Invalid permission(s): ban_member
解决方案
权限可能不正确,有权限ban_members
(注意复数)https://discordpy.readthedocs.io/en/stable/api.html#discord.Permissions.ban_members
推荐阅读
- c# - 在应用程序开始时创建注入对象,而不是在请求时
- google-cloud-dataflow - Apache Beam - 我应该了解编写高效数据处理管道的关键概念是什么?
- html - 为整个工具提示添加边框
- angular - 无法从 NGRX 状态显示选定的属性
- c# - unity rotation.eulerAngles.x 不工作?
- go - 如何在运行时收集已执行的行号
- reactjs - Material-UI Menu 组件只有最后一个 MenuItem onClick 动作被触发
- google-maps - 从静态地图更改谷歌地图示例应用程序脚本
- r - qqplot2中的LOESS置信区间过窄
- r - R类的顺序是什么导致的?