set_adminrole接受1个位置参数,但给出了2个

问题描述

所以我试图在我的机器人中创建一个设置命令,用户可以在其中选择他想要的东西。问题是我无法按自己的意愿运行它。

我以此为密码

# Function to write changes to file
def set_adminrole(guild: Guild,*,role: Role):
    with open("admins.json") as f:
        roles = json.load(f)

    roles[str(guild.id)] = role.id

    with open("admins.json",'w') as f:
        json.dump(roles,f,indent=4)

# Actual command

-- Not important code --

await ctx.send(f"Now,mention the role you want it to be the admin role")
    role: Message = await bot.wait_for("message",check=check)
    set_adminrole(ctx.message.guild,role.content)
    await ctx.send(f"Admin role changed to {Role(role.content).mention}... Let's keep going")

当我提到一个角色并尝试用它调用函数时,它给了我这个错误: TypeError: set_adminrole() takes 1 positional argument but 2 were given 预先感谢

解决方法

role是仅关键字的参数,因为它紧跟参数列表中的*。您需要将该值作为关键字参数而不是位置参数进行传递。

set_adminrole(ctx.message.guild,role=role.content)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...