删除角色(discord.py重写)

时间:2020-06-25 22:14:32

标签: python bots discord discord.py

现在我正在尝试发出删除角色的命令,并且试图摆脱过去创建角色的作用

@client.command()
async def createrole(ctx):
guild = ctx.guild
await guild.create_role(name="role")

我不知道该怎么办。

1 个答案:

答案 0 :(得分:0)

要删除角色,您需要比创建角色做更多的工作。您将需要在delete对象中使用Role函数。因此,如果要创建一个名为“删除角色”的命令,则需要先获取该角色对象,然后再将其删除。您可以执行以下操作:

@client.command(name="delete_role", pass_context=True)
async def delete_role(ctx, role_name):
    #find role object
    role_object = discord.utils.get(ctx.message.guild.roles, name=role_name)
    #delete role
    await role_object.delete()
相关问题