Home>

I already have a command that gives server members a specific role.

How now, by one more command, to remove this role from all members of the server?

  • Answer # 1

    Use the method
    Then iterate over the list of participants

    @ commands.command ()
    async def remove_role (self, ctx, role: discord.Role):
        for member in ctx.guild.members:
            if role in member.roles:
                await member.remove_roles (role)
    @ bot.command ()
    async def remove_role (ctx, role: discord.Role):
        for member in ctx.guild.members:
            if role in member.roles:
                await member.remove_roles (role)
    # without specifying the role
    @ bot.command ()
    async def remove_role (ctx):
        role= discord.utils.get (ctx.guild.roles, id= 'id role')
        for member in ctx.guild.members:
            if role in member.roles:
                await member.remove_roles (role)
    

    I don’t know where to set the name of the role.

    war hat2021-11-24 21:42:32

    ! remove_role @role

    RAINGM2021-11-25 06:48:54

    Works. Can I register a role within the team? So that I just write the command, and the bot removes the role, for example: Doctor. I tried through discrod.Role and role but nothing comes out

    war hat2021-11-25 10:26:17

    Yes, you can, made a change p.s. discord: RAINGM # 1941

    RAINGM2021-11-25 11:44:51