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

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

Discord.py 為用戶添加角色

Discord.py 為用戶添加角色

慕森王 2021-12-26 15:04:27
我是 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版本的小更新。


查看完整回答
反對 回復 2021-12-26
?
開心每一天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)


查看完整回答
反對 回復 2021-12-26
  • 2 回答
  • 0 關注
  • 151 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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