A Ryobi battery will typically go bad when it simply has exceeded its number of effective charges, has 1 or more cells that have an internal short, or has simply fallen below the minimum charging threshold for the charger.
In the latter case, the battery isn't necessarily bad, it just can't be recognized by the charger because the voltage is too low. However, this case can be reversed with a little hack.
Proceed with the steps outlined in this video at your own risk. This is for entertainment purposes only. Wear safety glasses if you proceed.
Remove the screws on the battery case and the tamper-plug (which will void your warranty, so please exchange your battery if it is still covered).
Check the voltage of each of the cells and see if they are relatively close to each other without any outliers.
If they are, and the overall voltage is just low, you can proceed with modifying the charger to bypass the battery control module that is mounted on the battery.
The steps in this video outline the process.
How to fix a Dewalt Battery: https://youtu.be/zsBydnTQkLM?si=IdN9EqTxtwEGDZa_
Website:
https://homebatterybank.com/diy-fix-for-a-ryobi-18v-battery-that-wont-charge/