I hate that kind of feeling. I had a hard time coping with it. I'd tell myself that it'd be better to die than to do some ♥♥♥♥ that everyone else can do better, no one likes me and if they do talk to me, there's definitely someone else better to hang out with. Fear might as well be my 2nd name. I kinda am going through these kinds of things currently.
But then I kept going. I didn't stop on the darkness that's happening now, because I KNOW that there is light on the road ahead, no matter how dim it might be, or how dark the road is. My point is to not give up, there is always the future.
I try to reject thoughts of doubt. I'd say them in my head (or really quietly) and follow up with a rebuttal. Music helps me escape thoughts, especially OSTs of games (since no lyrics means no being bogged down by words (though Son of Man is an exception)). Talking to people regularly at university also helps my sanity. Even if it is just small talk with a joke or two. It helps to have someone who can motivate you, or even just listen to you, and I'm glad I have someone like that. But even if your situation is difficult there are people willing to listen here (hence the topic).
Hopefully that provided some comfort. We just gotta keep going man, no matter how dark the road is