Let me start off by saying this, I've been there before and I know what you are feeling. As cliche as that sounds, it is always nice to know that someone knows and understands what you are feeling.
I have never been able to hold a steady healthy friendship. My freshmen year of high school I met this girl who was in my English class and we clicked instantly. We had so much in common it was insane.Sophomore year was when our friendship transitioned from a school friendship to a normal hang out all the time friendship. I felt like I could be myself around this person and I also felt like I didn't have to like all the same things as this person. Junior year things were going really well, we were still hanging out a lot. Then, senior came and I started hearing from her less and less. A lot of the times we only hung out when one of her other friends couldn't hang out with her. It was the classic case of "oh so and so said they couldn't hang out so I called you instead" or what I would like to call the second choice line. I spent a lot of nights wondering what I did wrong and thinking I wasn't good enough. I'm fine now. We are no longer friends and I'm happier than I've ever been.
Being alone when you don't want to be is one of the worst things to feel. Thinking that you're not good enough for someone impressions you in this mindset of poisonous thoughts that plague your mind with thoughts that do nothing but hurt you. Knowingly being the second choice friend is a prison sentence for your thoughts because you're left wondering what you did.
It's not your fault. You are in a tough position that you didn't ask to be in. You thought things were going well until they weren't. It's not your fault. You are good enough you just need to find someone that'll see that. It's not your fault that you are the second choice. The only piece of advice you're going to get is it find better friends, and that's okay. Yeah, you might not want to find different friends because you think that something is going to change, and they might.
You are enough. Just because some people you think are your friends don't see that doesn't mean it's not true. Don't keep thinking that your friends hate you. It can be tough going from being so close to a person that you would tell them anything and everything to only seeing them when they have no one to hang out with. There are people out there that will want to be your friend and want to spend time with you. Just because you haven't met them yet doesn't mean that you will never find them.
Sometimes it's good just to be on your own for a bit. You need to discover what you want in a friendship and what you want when it comes to friends. Friends will be some of the most valuable people in your life and sometimes it takes a couple crappy ones to find the perfect ones.