如何在discord.py中添加和创建角色?

时间:2018-01-11 22:36:18

标签: discord.py

我已经搜索了很多,试图找到一种方法,可以在discord.py中创建角色,但我还没有找到任何东西。我希望能够使用命令为用户创建和/或添加角色。我的代码是await client.create_role(message.author)

1 个答案:

答案 0 :(得分:2)

创建角色,

对于重写分支:

guild = ctx.guild
await guild.create_role(name="role name")

添加颜色,只需在create_role中添加colour=discord.Colour(0xffffff)作为选项,并将ffffff替换为颜色的十六进制代码

对于异步分支:

author = ctx.message.author
await client.create_role(author.server, name="role name")

添加颜色,就像重写分支一样。

现在,如果您想为用户添加角色,

对于重写分支:

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或更低的数字,则您具有异步分支

相关问题