Discord.py为用户添加角色 [英] Discord.py add role to user

查看:403
本文介绍了Discord.py为用户添加角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python的新手,并且一般情况下都创建不和谐的bot,我一生都无法弄清楚如何让bot能够根据用户的请求为用户分配角色.

I am new to python and creating discord bots in general and I can't for the life of me figure out how to make my bot assign a role to a user upon the users request.

我已经连续数小时搜寻互联网,并找到了一些示例,但它们都会产生错误.

I have scoured the internet for hours on end and have found a few examples but they all produce and error.

这是命令的代码:

@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.

推荐答案

删除has_role检查.检查调用方是否具有角色,以便他们可以为自己分配该角色,这没有任何意义.

Remove the has_role check. It doesn't make sense to check if the caller has a role so they can assign themselves that 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)

这篇关于Discord.py为用户添加角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆