Covalent organic frameworks (COFs) have recently demonstrated significant potential for photocatalysis. Optimizing the local electronic environment in COFs has been considered to be critical for enhancing photocatalytic activity. Here, we report a one-pot "grafting-to" strategy to reprogram the local electronic configurations of a series of isoreticular multicomponent COFs by introducing electron-donating or electron-withdrawing groups into the pores to transform photoinert to photoactive COFs and form intramolecular donor–acceptor (D-A) structures. Such D-A structures enhanced the overall hydrogen peroxide photoproduction by facilitating charge carrier separation and optimizing band structures to achieve the oxygen reduction reaction and water oxidation reaction simultaneously. Notably, the one incorporated with 2-aminothiazole exhibits a hydrogen peroxide production rate of 3701 μmol g–1 h–1 and solar-to-chemical conversion efficiency of 0.13% without the use of any sacrificial reagents, and it exhibits 100% bacterial killing rates and a remarkable >90% biofilm removal capability. This "grafting-to" COF modification strategy, which has not been reported before, offers a unique approach for constructing highly active COF photocatalysts containing intramolecular D-A structures and exhibits great potential in the future design of photocatalysts and antibacterial therapies.