code: def set_membership(self, room_id, user_id, membership, reason="", profile=None,
                         timestamp=None):
          
          if profile is None:
              profile = {}
          body = {
              "membership": membership,
              "reason": reason
          }
          if 'displayname' in profile:
              body["displayname"] = profile["displayname"]
          if 'avatar_url' in profile:
              body["avatar_url"] = profile["avatar_url"]
  
          return self.send_state_event(room_id, "m.room.member", body, state_key=user_id,
                                       timestamp=timestamp)
docs: Perform PUT /rooms/$room_id/state/m.room.member/$user_id
  
          Args:
              room_id (str): The room ID
              user_id (str): The user ID
              membership (str): New membership value
              reason (str): The reason
              timestamp (int): Set origin_server_ts (For application services only)