'else statment ignored discord python rewrite

The user is successfully muted if the bot detects "discord" in the custom signature. When user remove discord from custom signature, he not unmuted.

The else part of the code is completely ignored because I get no message/no error, it continue the loop ...

So, where i'm wrong in my code?

```@tasks.loop(seconds=10)
async def status_role():
    # ID guild
    guild = client.get_guild(1234567890)
    staff = discord.utils.get(guild.roles, name="Staff")
    role1 = discord.utils.get(guild.roles, name='Bot')
    muted = discord.utils.get(guild.roles, name="Muted")
    for member in guild.members:
        memberActivity = member.activity
        if memberActivity:
            # if staff or bo bot role => ignore both
            if staff in member.roles or role1 in member.roles:
                continue
            nameOfActivity = memberActivity.name
            # if discord is present in username of user
            if "discord" in nameOfActivity:
                # if already muted, continue
                if muted in member.roles:
                    continue
                else:
                    # if not muted => mute user
                    await member.add_roles(muted)
                    continue
            else:
                # if discord is not present in username of user
                if "discord" not in nameOfActivity:
                    # if user is muted, do remote mute below
                    if muted in member.roles:
                        await member.remove_roles(muted)
                        print('muted removed')
                        continue
print(status_role.current_loop)```

Im using google translate, sorry if my english is bad...

Discord rewrite:2.0.0a Python 3.9 Windows 10 x64

Thanks for your help



Solution 1:[1]

Ok, i assume your comments were correct. You need to remove 4 spaces from each of these lines:

            else:
                # if discord is not present in *username* of user
                if "discord" not in nameOfActivity:
                    # if user is muted, do remote mute below
                    if muted in member.roles:
                        await member.remove_roles(muted)
                        print('muted removed')
                        continue

Or in other words, remove one indent, this block triggers when if "discord" in nameOfActivity: fails, but it should trigger when if memberActivity: fails, at least i assume.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DharmanBot