discord.py on_member_update 删除成员拥有的所有角色

时间:2021-03-07 14:23:19

标签: python python-3.x discord discord.py

我想删除成员在 if game_after 时拥有的所有角色

我如何在这里for role in member.roles: await member.remove_roles(role)

当我做404 Not Found (error code: 10011): Unknown Role时我得到for role in member.roles: await member.remove_roles(role)

@commands.Cog.listener()
async def on_member_update(self, before, after):
    game_after = [i for i in after.activities if str(i.type) == "ActivityType.playing"]
    
        if game_after:
            game_name = game_after[0].name.strip()
            role = discord.utils.get(after.guild.roles, name=game_name)
            await after.add_roles(role)

1 个答案:

答案 0 :(得分:0)

问题是您试图删除everyone角色,所以idk如果这是您现在想要的但您可以配置它:

@commands.Cog.listener()
async def on_member_update(self, before, after):
    game_after = [i for i in after.activities if str(i.type) == "ActivityType.playing"]
    
        if game_after:
            game_name = game_after[0].name.strip()
            role = discord.utils.get(after.guild.roles, name=game_name)
            roles = after.roles[1:]
            await after.remove_role(*roles)