The answer to your question has two parts:
1) How to reduce the build up of static electricity.
Increase room (air) humidity. Low humidity tends to make static charge easier to occur. Indoor air during winter has lower humidity than during summer which is why static zaps tend to occur inside during the winter. You can buy a humidifier, or just use a spray bottle with water to increase humidity (water in the air).
Change any materials that build up static charge when rubbed against each other. The materials to be concerned about are the clothing you wear, your chair seat, the soles of your shoes, and your carpet. Your clothes rub against your other clothes and your chair seat, and your shoes rub against the carpet. Any plastic to plastic rubbing tends to build up static charge. Avoid polyester clothing and plastic chair seat covers. Natural materials such as cotton and leather don't build up static like plastic does.
Coat rubbing materials with anti-static chemicals. Dryer sheets are coated in these chemicals to reduce 'static cling'; use them on clothes and rub them on your chair seat and shoe soles. You can also buy commercial anti-static sprays or mix your own by combining water with liquid fabric softener, and then spray your carpet and chair seat.
You can wear an anti-static strap. These work, but only if you attach their grounding wire from the strap to a good ground point. They work by continuously draining any charge to the ground point, so that you never build up a charge.
2) When you already have a static charge, how to remove it safely.
Even once you have a static charge, there are ways of removing it without pain.
The pain of static zaps occur because the voltage buildup 'arcs' through the air during discharge, and discharge arc cause the zap pain you feel. In order to discharge the static buildup without pain, make the discharge occur in a place other than your skin.
Tightly grab a coin, key, metal ring, or any other conducting piece of metal (silver, copper, or aluminum work better than steel), and touch that metal to a (metal) grounding point (You know where these are; they are where you have gotten zapped before). For example, I tightly grip a quarter or house key between my fingers and touch the edge of the coin to a filing cabinet where I work.
You will hear the discharge zap, but not feel the pain because the discharge occurs between the coin or key and the discharge point. You will need to grip the coin tightly or you will still feel a little of the zap as it moves from your body through the coin, and you will need to keep your finger further from the ground point than the edge of the coin. If you wear a metal ring that can work as well.
One thing to beware of is zapping electronics. If the key or grounding point you use has electronics near or as part of them, static discharges may sometime destroy those electronics.