如何在discord.py中添加和创建角色? [英] How to add and create roles in discord.py?
问题描述
我进行了很多搜索,试图找到一种方法可以在discord.py中创建角色,但是我什么都没找到。我希望能够使用命令来创建和/或向用户添加角色。我的代码是 await client.create_role(message.author)
I have searched around a lot to try and find a way to be able to create roles in discord.py but I haven't found anything. I would like to be able to use a command to create and/or add roles to a user. my code is await client.create_role(message.author)
推荐答案
要创建角色,
对于重写分支:
guild = ctx.guild
await guild.create_role(name="role name")
要添加颜色,只需添加 colour = discord.Colour(0xffffff)
作为create_role中的选项,并将ffffff替换为颜色的十六进制代码。要向角色添加权限,请包括 permissions = discord.Permissions(permissions =< permission value>)
to add color, just add colour=discord.Colour(0xffffff)
as an option in create_role, and replace ffffff with the hex code for the color. To add permissions to the role, include permissions=discord.Permissions(permissions=<permission value>)
对于异步分支:
author = ctx.message.author
await client.create_role(author.server, name="role name")
添加颜色(可能还有权限),就像重写分支一样。
to add color (and probably permissions), just do the same as you would for the rewrite branch.
现在,如果要向用户添加角色,
Now, if you want to add roles to a user,
对于重写分支:
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或更低的数字,则您具有异步分支。要计算权限值,您可以使用此网站
To see which branch you have, do print(discord._version)
. If it says 1.0.0a, you have the rewrite branch. If it says 0.16.2 or a lower number, you have the async branch. To calculate permission values, you can use this website
这篇关于如何在discord.py中添加和创建角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!