How does sleep deprivation directly affect erections?
Most of a man’s testosterone is produced during sleep, with the highest amounts of testosterone being produced during REM (dreaming) sleep. And yes, scientists have determined that when men are deprived of sleep, their testosterone levels fall. A study of military recruits who were subject to major sleep deprivation reported testosterone levels falling by as much as 70%.
In most men, erectile dysfunction is caused by impaired blood flow rather than low testosterone levels, but low testosterone certainly doesn’t help matters. And plain old “being too tired for sex” is a real phenomenon, so don’t think of doing without sleep as a heroic thing.