0
@client.command(name="delete_role", pass_context=True)
async def delete_role(ctx):
    for role in ctx.guild.roles:
        if role.name != "Team" or "Team(OLD)" or "Admin" or "Админ" or "Rythm" or "Toxic Bot" or "@everyone":
            await role.delete()
            await ctx.send(f"deleted {role}")

I was trying to delete all roles on my server, but those which I choose.

1
  • Are you getting an error? or just didn't behave as expected? Commented Nov 28, 2020 at 16:42

1 Answer 1

3

Given you actual code, the expresion that you have on the if statement will always evaluate to True, because all non empty strings are evaluated to True in python.

>>> bool("")
False
>>> bool("a")
True

You can change your code to something like this

PRESERVE_USERS = [
    "Team", 
    "Team(OLD)", 
    "Admin", 
    "Админ", 
    "Rythm", 
    "Toxic Bot", 
    "@everyone",
]


@client.command(name="delete_role", pass_context=True)
async def delete_role(ctx):
    for role in ctx.guild.roles:
        if role.name not in PRESERVE_USERS:  
            await role.delete()
            await ctx.send(f"deleted {role}")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.