I think it is right to set the record straight that gambling in itself is addictive. Especially when you are already deeply rooted to gambling or you do it for fun and it will become a part of you. So since it is highly addictive, then loneliness can ignite your urge to gamble some more.
But we shouldn't make loneliness be the reason why we're gambling, we're in a social world and there are many things an individual can do to socialize and not get lonely. I think loneliness is a choice that we choose as if I ever feel lonely just a walk in the park and I'm back to been happy as I see nature and get to socialize with other individuals I see at the park. If you're a gambler and lonely is a problem for you, you can join clubs and keep yourself busy always to avoid been lonely.
We have clubs like book clubs and other clubs that hangout during the weeks, some do it once while other do it on multiple days so you can be actively busy and socializing always. You can also get a partner that'll keep you company so you don't feel lonely as loneliness can be the cause of many other issues you begin to develop and all leads to you not having good results when you're gambling.
There are still physical casinos in the world and in many countries,you can opt to go there to socialize with other fellow gamblers and if you are about to get addicted quite some other people that will stop you if they see you are about to do crazy things.In such physical casinos there are beautiful ladies serving free food and drinks so that is another good way to not feel lonely at all by interacting with them.I know that in this place it can spark addiction but if you go there with the intention of not feeling lonely that can be a great motive to stay and forget about the loneliness one can feel at certain points.