How to stop getting in these funks?

I sometimes get into a way emotionally/mentally where I just feel anxious or sad about life as a whole. I think the whole world is thinking about every wrong move I’ve done and everyone hates me but isn’t saying it or is planning to hurt me in some way. Why is that? No matter how many times I tell myself I’m fine it doesn’t work.
Updates
+1 y
In fact I’m in that mood right now and I left my job after hanging out with friends and I passed my technically ex and she was with her friends and they still talk to me but I felt like they were talking about me. I just don’t know right now who is a real friend or faking it for the moment.
How to stop getting in these funks?
Post Opinion