我是 python 的新手,通常會創建不和諧的機器人,我一生都無法弄清楚如何讓我的機器人根據用戶請求為用戶分配角色。我已經連續幾個小時在互聯網上搜索并找到了一些示例,但它們都產生并出錯。這是我的命令代碼:@client.command(pass_context=True)@commands.has_role("Bots")async def add_bot(ctx): member = ctx.message.author role = discord.utils.get(member.server.roles, name="Bots") await client.add_roles(member, role)這是我得到的錯誤:in _verify_checks raise CheckFailure('The check functions for command {0.qualified_name} failed.'.format(self))discord.ext.commands.errors.CheckFailure: The check functions for command add_bot failed.
2 回答

呼如林
TA貢獻1798條經驗 獲得超3個贊
對于重寫版本,事情發生了一些變化,add_roles不再client是discord.Member類的一部分,而是類的一部分,因此 discord.py 重寫版本的代碼是:
@client.command(pass_context=True)
async def add_role(ctx):
member = ctx.author
role = discord.utils.get(member.guild.roles, name="Bots")
await member.add_roles(role)
REWRITE版本的小更新。

開心每一天1111
TA貢獻1836條經驗 獲得超13個贊
取下has_role支票。檢查調用者是否具有角色以便他們可以為自己分配該角色是沒有意義的。
@client.command(pass_context=True)
async def add_bot(ctx):
member = ctx.message.author
role = discord.utils.get(member.server.roles, name="Bots")
await client.add_roles(member, role)
添加回答
舉報
0/150
提交
取消