[英]How to add and create roles in discord.py?
我已经搜索了很多,试图找到一种在 discord.py 中创建角色的方法,但我没有找到任何东西。 我希望能够使用命令为用户创建和/或添加角色。 我的代码是:
await client.create_role(message.author)
要创建角色,
对于重写分支:
guild = ctx.guild
await guild.create_role(name="role name")
要添加颜色,只需在 create_role 中添加colour=discord.Colour(0xffffff)
作为选项,并将ffffff
替换为颜色的十六进制代码。 要为角色添加权限,请包括permissions=discord.Permissions(permissions=<permission value>)
对于异步分支:
author = ctx.message.author
await client.create_role(author.server, name="role name")
要添加颜色(可能还有权限),只需执行与 rewrite 分支相同的操作即可。
现在,如果您想为用户添加角色,
对于重写分支:
role = discord.utils.get(ctx.guild.roles, name="role to add name")
user = ctx.message.author
await user.add_roles(role)
对于异步分支:
user = ctx.message.author
role = discord.utils.get(user.server.roles, name="role to add name")
await client.add_roles(user, role)
要查看您拥有哪个分支,请执行print(discord._version)
。 如果它显示 1.0.0a,则您有重写分支。 如果它显示 0.16.2 或更低的数字,则您有 async 分支。 要计算权限值,您可以使用此网站
注意:Discord.py 目前是 1.6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.