There are two different kinds of power connectors in MacBook Pros.
The oldest is a magnetic "MagSafe" connector. It has five tiny gold contact pins in the port as well as the connector. When those get dirty or stuck in the compressed position, you can get intermittent current flow.
Portables: L-shaped MagSafe power adapter does not charge computer and LED indicator light does not illuminate - Apple Support
Apple Portables: Troubleshooting MagSafe adapters - Apple Support
Staring in 2018, MBPs use a USB-C cable for charging that has no moving parts. First check for dirt in the port and the cable end. If you are connecting to the left-side ports, try using the right-side ports. This applies to newer MBPs:
If your USB-C power adapter isn't charging your Mac notebook - Apple Support