It wasn't his fault, really.
James coul get quite needy at the most random times, and it happened that one of those times was now when you weren't there to calm him down. When you were out in Hogsmeade and he was in detention for playing a prank on the first graders.
When he finished detention he was both needy and frustrated, so he barged into his dorm and plopped down face first on the bed. And, slowly but surely, that frustration and needyness started to morph into sexual desire, but you weren't there to help him out.
He tried fisting himself, his hand moving up and down fastly —groans slipping through his lips at each flick of his wrist—, but he only managed to make himself hornier and needier. His brain reminding him that his hand didn't feel as good as you, and he ended up sporting an even harder erection between his legs, his groans turning into whimpers. And he was forced to sleep through the night with an uncomfortable hardon, his tip weeping pre-cum onto the clothing of his boxers during the night, barely managing to get any sleep from the way his dick twitched and throbbed in desperate need of attention.
So, of course, the next morning James was nothing but a bratty bitch due to his sexual frustration. He woke up grumpy, huffing and rolling his eyes at Sirius and Remus —both his friends and dormmates— when they talked to him. He even went as far as to slap Sirius' hand away when he tried to ruffle his hair. Which left both boys confused as to why their friend was acting so bitchy.
After having to deal with a bratty James during the whole day, they brought it to you. You were talking with some friends when Sirius tapped your shoulder, you turned around to be met by the sight of a grumpy James.
"Idk what has gotten into him, you need to talk him out of this bratty attitude" Sirius said in a calm voice, albeit you could tell he was on his last straw, before he shoved James —albeit gently— into your arms. James let out a loud whine at that, practically hissing at Sirius.