Try an SMC reset.
Check the condition of the battery. Option-click the battery icon on the menubar. Any condition other than "Normal" or "Good" means the battery should be replaced.
Run the Apple Diagnostics.
If this is a USB-C laptop, then try using another USB-C port especially on the other side of the laptop if you have the Touchbar model. Also plug the charger directly into the laptop instead of any dongles, adapters, or hubs.
See these Apple articles for troubleshooting a Magsafe or USB-C charging issue.
Unplug the charger from the electrical outlet for a minute to reset the charger's internal circuitry. Also try using another electrical outlet.
If you still have problems then have your laptop checked out by Apple or an AASP or click on the "Contact Support" link at the top right of this page.
Edit: See if your laptop qualifies for any of these publicly acknowledged free Apple repair programs:
https://support.apple.com/exchange_repair