我正在尝试建立一个“系统”,人们可以在其中更改有权访问管理命令的角色,但是它给我带来了一个错误,我不明白这是怎么可能的
代码:
def get_prefix(client, message):
with open("prefixes.json", 'r') as f:
prefixes = json.load(f)
return prefixes[str(message.guild.id)]
@bot.command(name="changeadminrole", help="Choose the role that can execute admin commands")
async def changeadmin(ctx, role: Role):
with open("admins.json", 'r') as f:
admins = json.load(f)
admins[str(ctx.guild.id)] = role.name
with open("admins.json", 'w') as f:
json.dump(admins, f, indent=4)
await ctx.send(f"Admin role changed to {role.mention}")
然后,要检查人员是否具有所需的角色,我只需执行以下操作:
@bot.command(name="kick", help="Kicks a member from the server")
@commands.has_role(get_adminrole)
即使我有这个角色,它也会让我犯这样的错误:
discord.ext.commands.errors.MissingRole: Role <function get_adminrole at 0x03977220> is required to run this command.
Idk为什么检索(<function get_adminrole at 0x03977220>
)而不是admins.json
文件中的角色名称:
{
"506201000374435850": "Absolute Admin"
}
谢谢你的帮助
这是我用来做这件事的全部代码
我刚得到这个角色,你可以继续剩下的代码
最好保存角色id而不是名称,这样就可以跳过
role = ....
而只return admins[str(message.guild.id)]
下面是一个如何使用kick命令的变通方法
相关问题 更多 >
编程相关推荐