I suffered from lonliness for too long but about a year ago I stopped and thought: wait a minute, is being alone that bad??
I had to keep a very toxic people in my life so that I dont feel alone because being alone was once a nightmare for me.
Here is a saying that I like the most "if you are not happy alone, you will not be happy with anyone else"
Only when you start enjoying being alone, you will start building healthy relationships with others, when you make others responsible for your happiness, you will suffer even if you were around tons of friends, simply because no one can make anyone happy!! not even your boy/girl friend.
Its okay if someone does not want to be your friend, or you find someone that you do not like to be around.
Find a hobby, read good books or practice an instrument, make relationships with people a trivial thing in your life and only then, you will be able to make good relationships.