Engineering photocatalysts to enhance the production of reactive oxygen species holds great importance in realizing effective water purification and hydrogen peroxide (H2O2) generation. Herein, the K, O, and cyano co-modified carbon nitride (KOCN) was constructed using thermal polymerization. Under visible light irradiation, KOCN showed excellent oxytetracycline hydrochloride (OTC) degradation efficiency and H2O2 generation rate. During the photocatalysis, rich reactive oxygens involving ·O2-, 1O2, H2O2, and ·OH were detected. Additionally, the production of H2O2 was attributed to a two-step single-electron oxygen reduction reaction (ORR). DFT and characterization analyses confirmed that the doping of K and O as well as the formation of cyano groups expanded the visible light response range, adjusted the band structure, and improved the separation of photogenerated carriers. This study presents a novel approach for developing efficient, stable, and reusable photocatalysts to address contemporary environmental challenges.