Reputation: 93
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")
Upvotes: 2
Views: 464
Reputation: 1207
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)
Upvotes: 1
Reputation: 637
First, get the role using one of discord.py's utility functions (https://discordpy.readthedocs.io/en/latest/api.html#discord.utils.get):
role = discord.utils.get(ctx.guild.roles, name=name)
Then delete the role (https://discordpy.readthedocs.io/en/latest/api.html#discord.Role.delete):
await role.delete()
Upvotes: 2
Reputation: 191
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")
Upvotes: 1