如何在 discord.py 中添加和创建角色? [英] How to add and create roles in discord.py?

查看:125
本文介绍了如何在 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")

要添加颜色,只需在 create_role 中添加 colour=discord.Colour(0xffffff) 作为选项,并将 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 或更低的数字,则您有 async 分支.要计算权限值,您可以使用 this 网站

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 目前为 1.6

note: Discord.py is currently at 1.6

这篇关于如何在 discord.py 中添加和创建角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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