I was making my mute command and I thought of getting rid of all the member's role but I don't know how to get rid of all the member's roles I even tried
for role in member.roles:await member.remove_roles(role)
But it gave me this error:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NotFound: 404 Not Found (error code: 10011): Unknown Role
Any suggestion or ideas!
My code:
@commands.command()@commands.has_permissions(administrator=True)async def mute(self, ctx, member: discord.Member=None, reason="No reason provided", *, time: time_str.convert = datetime.timedelta(seconds=0)):guild = ctx.guildmuted_role = discord.utils.get(guild.roles, name="Muted")time_converted = time.total_seconds()if member is None:await ctx.send("You need to mention someone in order to mute them")returnif member == ctx.author:await ctx.send("You can't mute yourself")returnif muted_role in member.roles:await ctx.send("They are already muted")returnif muted_role is None:await guild.create_role(name="Muted")else:if time_converted == 0: mutedembed = discord.Embed(title="**Muted!**")mutedembed.add_field(name=f'ID:', value=f'{member.id}', inline=False)mutedembed.add_field(name=f"Name:", value=f"{member.name}#{member.discriminator}")mutedembed.add_field(name=f'Reason:', value=f"{reason}")mutedembed.add_field(name="Time", value=time)mutedembed.add_field(name=f'By:', value=f'{ctx.author.name}#{ctx.author.discriminator}', inline=False)mutedembed.set_thumbnail(url="")await ctx.send(embed=mutedembed)for role in member.roles:await member.remove_roles(role)await member.add_roles(muted_role)if time_converted == 1 or time_converted > 1:tempmutedembed = discord.Embed(title="**Temp Muted!**")tempmutedembed.set_author(icon_url=member.avatar_url, name=f'{member} has been temp muted!')tempmutedembed.add_field(name=f'ID:', value=f'{member.id}', inline=False)tempmutedembed.add_field(name=f"Name:", value=f"{member.name}#{member.discriminator}")tempmutedembed.add_field(name=f'Reason:', value=f"{reason}")tempmutedembed.add_field(name=f"Time", value=time)tempmutedembed.add_field(name=f'By:', value=f'{ctx.author.name}#{ctx.author.discriminator}', inline=False)tempmutedembed.set_thumbnail(url=f"https://media.discordapp.net/attachments/818899477372600434/835563020402556938/1200px-Bw-muted.png?width=586&height=586")tempmutedembed.set_footer(text=f"{ctx.author.name}#{ctx.author.discriminator}", icon_url=ctx.author.avatar_url)await ctx.send(embed=tempmutedembed)for role in member.roles:await member.remove_roles(role)await member.add_roles(muted_role)await asyncio.sleep(time_converted)unmutedembed = discord.Embed(title="**UnMuted!**")unmutedembed.set_author(icon_url=member.avatar_url, name=f'{member} has been temp muted!')unmutedembed.add_field(name=f'ID:', value=f'{member.id}', inline=False)unmutedembed.add_field(name=f"Name:", value=f"{member.name}#{member.discriminator}")unmutedembed.set_thumbnail(url=f"")unmutedembed.set_footer(text=f"{ctx.author.name}#{ctx.author.discriminator}", icon_url=ctx.author.avatar_url)await ctx.send(embed=unmutedembed) await member.remove_roles(muted_role)
Thanks for all of your support. It helps alot!