亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

set_adminrole() 采用 1 個位置參數,但給出了 2 個

set_adminrole() 采用 1 個位置參數,但給出了 2 個

嚕嚕噠 2023-05-16 15:48:42
所以我試圖在我的機器人中創建一個設置命令,用戶可以在其中選擇他想要的。問題是我無法讓它按照我的意愿工作。我有這個作為我的代碼# Function to write changes to filedef 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 提前致謝
查看完整描述

1 回答

?
守著一只汪

TA貢獻1872條經驗 獲得超4個贊

role是僅關鍵字參數,因為它*在參數列表中跟在 之后。您需要將值作為關鍵字參數而不是位置參數傳遞。

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


查看完整回答
反對 回復 2023-05-16
  • 1 回答
  • 0 關注
  • 157 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號