使用edit_role discord.py编辑角色

时间:2019-02-20 21:51:53

标签: python-3.x discord.py

我的脚本中包含以下行:

await client.edit_role(server='547874634978789398', role='' ,colour=0x008000)    

但是,我不知道对role=期望使用discord.py参数是什么。谁能指出我正确的方向,以便更好地理解此参数?

2 个答案:

答案 0 :(得分:0)

首先,您应该使用Server类而不是服务器的ID。有get_server()函数返回具有给定服务器ID的Server对象。

server = client.get_server('547874634978789398')

然后,您可以通过server.roles访问属于服务器的所有角色。它是list对象的Role。因此,如果您有角色的名称,并且想要将其角色编辑为该角色,请尝试一下。

for role in server.roles:
    if role.name == 'role_name':
        # What you want to do.
        await client.edit_role(server=server, role=role, colour=0x0080000)
        break

还有server.role_hierarchy属性,该属性按层次结构顺序返回角色。它包含与server.roles相同的元素,但它是已排序的版本。

答案 1 :(得分:0)

role = discord.utils.get(ctx.guild.roles, name="Name")
# This will get the role you want to edit
await role.edit(color=0x008000, reason="The reason")
# This will edit the role with the desired color

有关此的更多信息,请参阅文档:discord.Role.edit | discord.utils.get