In this work, the feasibility of using transition metal doped C9N4 as an efficient gas sensor is comprehensively investigated by density functional theory methods. Firstly, the calculated Ef and Udiss values show that most of M-C9N4 and M2-C9N4 have good thermodynamic and electrochemical stability. Secondly, for CO, NO, NO2, NH3, and H2S on Cr-C9N4, the Eads values are −2.07, −3.05, −2.53, −1.76, and −2.14 eV, respectively. For these gases on Fe2-C9N4, the Eads values are −2.60, −3.07, −2.45, −2.39, and −2.21 eV, respectively. The results show that Cr-C9N4 and Fe2-C9N4 have good adsorption strengths for all gases, which can provide good theoretical guidance for the design of excellent sensing materials. Finally, by calculating band structures of all catalysts, they all have small band gap values, such as, Fe2-C9N4 with the 0.10 eV, which all shows stable catalysts possess good conductive properties. The DOS results show that there is an obvious orbital hybridization between metal, N, C, and O atoms, indicating that there is a certain interaction between them, which is an important factor leading to the good adsorption of the catalyst to the molecular gas. This work can provide theoretical guidance for searching efficient sensor materials.