Regulating the electron structure and precise loading sites of metal-active sites within the highly conjugated and porous covalent-triazine frameworks (CTFs) is essential to promoting the nitrogen reduction reaction (NRR) performance for electrocatalytic ammonia (NH3) synthesis under ambient conditions. Herein, experimental method and density functional theory (DFT) calculations were conducted to deeply probe the effect on NRR of the modulation of modulating the electron structure and the loading site of gold nanoparticles (Au NPs) in a two-dimensional (2D) CTF. 2D CTF synthesized using melem and hexaketocyclohexane octahydrate as building blocks (denoted as M−HCO−CTF) served as a robust scaffold for loading Au NPs to form an M−HCO−CTF@AuNP hybrid. DFT results uncovered that well-defined Au sites with tunable local structure were the active site for driving the NRR, which can significantly suppress the conversion of H+ into *H adsorption and enhance the nitrogen (N2) adsorption/activation. The overlapped Au (3d) and *N2 (2p) orbitals lowered the free energy of the rate-determining step to form *NNH, thereby accelerating the NRR. The M−HCO−CTF@AuNPs electrocatalyst exhibited a large NH3 yield rate of 66.3 μg h−1 mg−1cat. and a high Faraday efficiency of 31.4 % at − 0.2 V versus reversible hydrogen electrode in 0.1 M HCl, superior to most reported CTF-based ones. This work can provide deep insights into the modulation of the electron structure of metal atoms within a porous organic framework for artificial NH3 synthesis through NRR.