Have you tried to reset the charging logic of the device, first you must charge your M8 for a minimum of 10 minutes using a wall charger. With the power off, press down and hold the volume up and down button with the power button for approximately 2 minutes. After 2 minutes, release all of the buttons. After the release the charging logic should be reset. Then charge your phone to 100% using your wall charger. If this doesn't work then its probably a failing battery or charge port.
I am curious what charger you have used to charge the battery. If you are using a generic charger or one that you had from a previous phone it may have caused damage to the battery or the charging IC on the motherboard. This is because the charger is sending the wrong voltage to charge the battery. If you were using the charger that htc recommends then the power IC should be fine, but the battery may still be the cause. If a Li-ion battery discharges to low it usually has a protective circuit built in that will put the battery in sleep mode when it drops below a certain voltage(I think around 2.8v-3v). When this happens the only way to get the battery out of that state it to give it a boost charge. Same idea as jumping a car battery. It needs a higher current for a short time to boost the battery above 3v then you can charge with a regular charger. Anywhere under 3.4v the phone won't power on but can still be charged without a boost if it doesn't go into protective mode. The protective mode keeps the battery from over voltage and under voltage. These batteries will discharge at faster rates if exposed to the wrong conditions. The battery may possibly be faulty and needs replaced.
Can you plug it into a PC and have the PC recognize the M8? Will it charge or light up the LED when connected to a PC's usb port? If not you should examine the M8 charge port for damage. The charge port may be damaged or dirty and preventing the phone from charging or being recognized by PC.