Really sorry to hear this!
I think the first thing to say is you're not alone, I can guarantee that. The thing with university is people who are feeling lonely/sad/unsettled are in most cases the people you won't see very often because they'll prefer to stay in their room.When it comes to school it's a bit different because you have to attend everything whether you're comfortable/lonely or not. I think it's also harder to find the friends who are absolutely right for you, even though there's a lot more people to choose from, as it were, because there are less occasions when you are forced to make conversation. Like you won't be doing much talking in lectures and wont have to find someone to have lunch with in the canteen at university.
But it does sound like you're struggling with more than just loneliness. I suppose what's worth thinking about is whether loneliness is causing you to also feel like York is a horrible place and your course isn't good, or whether maybe not liking York is causing you to not enjoy your course, or if not enjoying your course is causing you to be lonely etc... etc... So basically if you hate everything at university or if theres something in particular you dislike which is making everything else feel bad, if you get what I mean. That could perhaps help you identify what could be done to make you feel better. If you would like to talk about this more please feel free to DM me, I'm in third year now but had a really rough first year so I can relate to what you're going through. What you can maybe take heart from is over time things have got a lot better for me and I really feel at home here now