The development of novel materials with dual functions of simultaneous detection and removal of heavy metal ions has been an important pursuit of environmental remediation. Herein, we demonstrate that two-dimensional covalent organic frameworks (COFs) with well-defined functional chelating sites can combine the inherent advantages of COF materials to prepare novel materials with the dual functions of selective detection and effective removal of Ni²⁺ from aqueous solutions. A new pyridine-based COF material (TAPA-PCBA) containing functional N,N,N-chelating sites has been designed and synthesized by the imine condensation reactions between tris(4-aminophenyl)amine and 2,6-pyridinedicarboxaldehyde under solvothermal conditions. The newly designed TAPA-PCBA possesses high crystallinity, moderate specific surface area and robust chemical and thermal stability. These excellent properties of TAPA-PCBA, together with its extended π-conjugated framework structure and the dense distribution of functional N,N,N chelating sites, enable TAPA-PCBA to selectively detect and effectively remove Ni²⁺ from aqueous solutions. This dual function can be attributed to the coordination interactions between Ni²⁺ and N,N,N-chelating sites embedded in the skeleton structure of TAPA-PCBA. These results reveal that COFs with reasonable design have great development prospects in heavy metal ion related environmental remediation.