queen
queen

Reputation: 3

How do I delete all discord roles the simple way?

I have a bunch of servers where I would like to delete all the roles that I previously made, but their number leaves much to be desired...

Instead of the traditional mentioning of said roles (which is flawed, and quite slow) I haven't been able to find out how to code it so the command can be run and all roles below the bot can be deleted, automatically.

code I came up with:

async def delrole(ctx, *, roles: discord.Role):
    for role in roles:
        try:
            await client.delete_role(ctx.message.guild, role)
        except discord.Forbidden:
            await client.say("Cannot delete this role!")

Any input would be much appreciated! Thanks

Upvotes: 0

Views: 308

Answers (1)

Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15689

You're using the old async version of discord.py, here's your fixed code:

for role in ctx.guild.roles:
    try:
        await role.delete()
    except discord.Forbidden:
        await ctx.send(f'Cannot delete this role {role}')

Please read the documentation of discord.py-rewrite

Upvotes: 1

Related Questions