This seems to be available as a first party config option
Mine's set to "Only on Power Adapter", which makes sense.
Edit: On an M4 MacBook Air running macOS 26 DB
> sudo pmset -a powernap 1
-a is an option to set it for battery and plugged-in. If you want only either you can do -b for battery, -c for charger
You can also check the settings with:
> pmset -g