cogs/color/assignment.py
async def on_member_update(self, before, after):
        """Updates color info if a users color role is manually removed"""
        # check if any roles changed
        if before.roles == after.roles:
            return

        # convert roles to set for comparison
        roles_before = set(before.roles)
        roles_after = set(after.roles)

        # find difference between sets
        removed_roles = roles_before - roles_after
        added_roles = roles_after - roles_before

        # Role removed
        for role in removed_roles:
            response = db.guilds.update_one(
                {"_id": after.guild.id, "colors.role": role.id},
                {"$pull": {"colors.$.members": after.id}}
            )

            # clear role if empty
            if not role.members and response.matched_count == 1:
                try:
                    await role.delete()
                except discord.errors.NotFound:
                    pass
                except discord.Forbidden:
                    pass

        # Role added
        for role in added_roles:
            db.guilds.update_one(
                {"_id": after.guild.id, "colors.role": role.id},
                {"$push": {"colors.$.members": after.id}}
            )
Updates color info if a users color role is manually removed
Updates color info if a users color role is manually removed
Updates color info if a users color role is manually removed
async def on_member_update(self, before, after):
        if before.roles == after.roles:
            return
        roles_before = set(before.roles)
        roles_after = set(after.roles)
        removed_roles = roles_before - roles_after
        added_roles = roles_after - roles_before
        for role in removed_roles:
            response = db.guilds.update_one(
                {"_id": after.guild.id, "colors.role": role.id},
                {"$pull": {"colors.$.members": after.id}}
            )
            if not role.members and response.matched_count == 1:
                try:
                    await role.delete()
                except discord.errors.NotFound:
                    pass
                except discord.Forbidden:
                    pass
        for role in added_roles:
            db.guilds.update_one(
                {"_id": after.guild.id, "colors.role": role.id},
                {"$push": {"colors.$.members": after.id}}
            )
async def on_member_update ( self , before , after ) : if before . roles == after . roles : return roles_before = set ( before . roles ) roles_after = set ( after . roles ) removed_roles = roles_before - roles_after added_roles = roles_after - roles_before for role in removed_roles : response = db . guilds . update_one ( { "_id" : after . guild . id , "colors.role" : role . id } , { "$pull" : { "colors.$.members" : after . id } } ) if not role . members and response . matched_count == 1 : try : await role . delete ( ) except discord . errors . NotFound : pass except discord . Forbidden : pass for role in added_roles : db . guilds . update_one ( { "_id" : after . guild . id , "colors.role" : role . id } , { "$push" : { "colors.$.members" : after . id } } )
Updates color info if a users color role is manually removed
Updates color info if a users color role is manually removed
"""Updates color info if a users color role is manually removed""" # check if any roles changed # convert roles to set for comparison # find difference between sets # Role removed # clear role if empty # Role added
self
before
after