How to delete roles using discord.py?

Viewed 359

I am trying to create a command that deletes a specified role when you type it in. But it doesn't work. I've searched up solutions but only found tutorials in async, and I am using rewrite. Can anyone help me? Here is my code:

@client.command()
async def delrole(ctx, *, name):
    await ctx.guild.remove_roles(name)
    await ctx.send(f"Succesfully deleted the {name} role")
3 Answers

Probably like this

role = discord.utils.get(ctx.guild.roles, name = "role_name")
await bot.delete_role(ctx.guild, role)
await bot.send(f"Succesfully deleted the {role.name} role")
    

remove_role is for removing roles from a Member.

To delete a role you need to use delete_role

An example as follows:

guild = ctx.guild
role = discord.utils.get(guild.roles, name = "role's name")
await client.delete_role(guild, role)
Related