Peanuts are easily contaminated by a variety of mycotoxins during growth, transportation, and storage, of which aflatoxin B1 is the most common. Aflatoxin B1 is one of the most toxic carcinogens known, and it can cause liver damage to varying degrees after ingestion. To explore the feasibility of detecting aflatoxin B1 contamination in peanuts by near-infrared spectroscopy, 115 peanut samples with aflatoxin B1 content in the range of 2.44 to 223.76 μg/kg were prepared. The near-infrared spectroscopy data of the peanut sample in the 940–1660 nm band was obtained, and the naive Bayes qualitative discrimination model based on the whole band was established. To improve accuracy and reduce dimensions, simplified models were built using characteristic wavelengths screened by Successive Projection Algorithm and Elimination of Uninformative Variables. The built model is verified internally and externally by omitting cross-validation. In comparison, the second derivative Savitzky–Golay Elimination of Uninformative Variables normal kernel density estimation naive Bayes model reached the optimum discriminant accuracy, with the comprehensive overall accuracy of validation set and prediction set were over 91.00%, areas under receiver operating characteristic curves was over 0.90. The results showed that the accuracy of the quantitative determination of aflatoxin B1 in peanuts by near-infrared spectroscopy was high, with a boundary of 20 μg/kg. This method is suitable for the qualitative determination of peanut aflatoxin B1.