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 提前致谢


噜噜哒
浏览 142回答 1
1回答

守着一只汪

role是仅关键字参数,因为它*在参数列表中跟在 之后。您需要将值作为关键字参数而不是位置参数传递。set_adminrole(ctx.message.guild, role=role.content)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python