0
votes

I am trying to add a mute command in my dicord.py and discord.ext.commands bot, and since other discord roles do not let "Muted" role operate properly, I have to remove all roles from member before assigning a "Muted" role to the member. Everything seems fine but I can't get along with member.roles list which through print() seems fine and shows each role's name or ID but it gives me this error:

NotFound: 404 Not Found (error code: 10011): Unknown Role

I tried changing different types of member.roles list but none of them work

@client.command()
@commands.has_any_role('Admin', 'Mod', 'Owner')
async def mute(ctx, member: discord.Member = None):
    for i in range(100):
        try:
            print(member.roles[i])
            await member.remove_roles(member.roles[i])
        except IndexError:
            print('Something happened, maybe index out of range?')

    role = ctx.guild.get_role(781129235079233586)
    mute_message = ('Muted ' + str(member))
    print(mute_message)
    await member.add_roles(role)
    await ctx.send(mute_message)

I also tried using role's ID instead of name

id(member.roles[i])

But I get this:

Command raised an exception: AttributeError: 'int' object has no attribute 'id'
1

1 Answers

0
votes

Your loop are not setup correctly. You should look Member.roles.

Note: It is a bad practice using for i in range(100) You can loop directly.

for role in member.roles:
    await member.remove_roles(role)