【问题标题】:How to add and create roles in discord.py?如何在 discord.py 中添加和创建角色?
【发布时间】:2018-06-21 08:44:29
【问题描述】:

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

【问题讨论】:

    标签: discord.py


    【解决方案1】:

    要创建角色,

    对于重写分支:

    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")
    

    要添加颜色(可能还有权限),只需执行与重写分支相同的操作即可。

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

    对于重写分支:

    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网站

    注意:Discord.py 目前是 1.6

    【讨论】:

    • 如何添加特定权限?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 2020-09-13
    • 2021-05-05
    • 1970-01-01
    • 2021-07-26
    • 2021-03-26
    相关资源
    最近更新 更多