Background. The purpose of this study was to evaluate the effect of diet and antihyperglycemic drugs on erectile dysfunction (ED) in a setting of subjects affected by diabetes mellitus (DM) or preDM. Methods. This is a prospective observational study on 163 consecutive subjects with preDM or DM. All patients have undergone a medical evaluation (age, Body Mass Index (BMI), family history of DM, duration of DM, smoking, physical activity, dyslipidemia, cardiovascular comorbidities, and testosterone and HbA1c levels) and the International Index of Erectile Function (IIEF)-5 questionnaire. Results. Overall, the mean age was 62.8 ± 9.3 years, and the mean BMI was 28.4 ± 4.6 kg/m2. The IIEF-5 score mean value was 14.4 ± 6.2 (range 4–25). Among all confounders investigated for their association with the IIEF-5 score, only age and the duration of DM among diabetic patients showed a significant trend. The IIEF-5 score was higher in patients using GLP-1a compared to insulin (16.7 ± 4.7 vs. 12.9 ± 6.2; p = 0.02). This association was confirmed after adjustment for age and duration of DM (p = 0.01). All other treatments were similar (14.9 ± 6.2, 14.8 ± 9.2, 15.3 ± 5.4, and 13.6 ± 6.8 for metformin, sulfonylureas (SU), dipeptidyl-peptidase-4 inhibitors (DPP-4i), and sodium-glucose cotransporter-2 inhibitors (SGLT2i) treatment, respectively). Conclusions. This prospective observational study increases attention and focus on the effect of antihyperglycemic drugs and diet on ED, above all about the role of new classes, showing a significant higher IIEF-5 mean value in patients using GLP-1a compared to patients on insulin treatment.