The nitrogen-doped carbons (NC) were prepared by a simple pyrolysis method using polyaniline as the precursor. The effect of carbonization temperature on the properties of the synthesized NC was investigated. The optimal temperature was determined as 600 °C according to the properties of the obtained materials and the performance on improving the methane production by the anaerobic sludge. When the optimal NC was used as the conductive medium in the anaerobic sludge, the methane yield and production rate were increased by 35% and 10%, respectively. The effect of the NC loading on the activity of the microorganisms was also investigated. It was found that the degradation of the organics in the bacteria was enhanced by adding NC. Moreover, the bacterial and archaeal communities were significantly affected by the added NC material, and Methanosaeta with the direct interspecific electron transfer (DIET) ability have been enriched in anaerobic sludge. This indicated that the NC materials with surface defects can improve the organics degradation and the microbial extracellular electrons transfer, thereby promoting the methane production during the anaerobic wastewater treatment.