Critical-sized bone defect repair in patients with diabetes mellitus remains a challenge in clinical treatment because of dysfunction of macrophage polarization and the inflammatory microenvironment in the bone defect region. Three-dimensional (3D) bioprinted scaffolds loaded with live cells and bioactive factors can improve cell viability and the inflammatory microenvironment and further accelerating bone repair. Here, we used modified bioinks comprising gelatin, gelatin methacryloyl (GelMA), and 4-arm poly (ethylene glycol) acrylate (PEG) to fabricate 3D bioprinted scaffolds containing BMSCs, RAW264.7 macrophages, and BMP-4-loaded mesoporous silica nanoparticles (MSNs). Addition of MSNs effectively improved the mechanical strength of GelMA/gelatin/PEG scaffolds. Moreover, MSNs sustainably released BMP-4 for long-term effectiveness. In 3D bioprinted scaffolds, BMP-4 promoted the polarization of RAW264.7 to M2 macrophages, which secrete anti-inflammatory factors and thereby reduce the levels of pro-inflammatory factors. BMP-4 released from MSNs and BMP-2 secreted from M2 macrophages collectively stimulated the osteogenic differentiation of BMSCs in the 3D bioprinted scaffolds. Furthermore, in calvarial critical-size defect models of diabetic rats, 3D bioprinted scaffolds loaded with MSNs/BMP-4 induced M2 macrophage polarization and improved the inflammatory microenvironment. And 3D bioprinted scaffolds with MSNs/BMP-4, BMSCs, and RAW264.7 cells significantly accelerated bone repair. In conclusion, our results indicated that implanting 3D bioprinted scaffolds containing MSNs/BMP-4, BMSCs, and RAW264.7 cells in bone defects may be an effective method for improving diabetic bone repair, owing to the direct effects of BMP-4 on promoting osteogenesis of BMSCs and regulating M2 type macrophage polarization to improve the inflammatory microenvironment and secrete BMP-2.