How do you stop wanting to be with someone when your mental state isn’t good?

I’ve been struggling with this for a very long time. I know full well my mental state isn’t the best but there’ll be times where I want to be with someone. I always end up feeling bad for having those feelings so I try to get rid of them.
How do you stop wanting to be with someone when your mental state isn’t good?
Post Opinion