Java 26.2
Damage Command
@pDamage
@p
/damage @p 4 minecraft:generic
Damage context
The /damage command does more than subtract hearts: the damage type decides whether armor and enchantments apply, and the by/from context decides the death message and kill credit. Set the amount, the type and the context here instead of memorising the argument order.
The damage type decides whether armor and enchantments apply. A type flagged to bypass armor (like magic or out-of-world) hits full, while a physical type is reduced. Pick the type that matches the effect you want.
Use the by context (and optionally from) to attribute the damage to an entity. /damage @p 10 minecraft:player_attack by <attacker> sets kill credit and the death message accordingly.
No -- /damage is a newer Java command. Bedrock has no direct equivalent, so the generator marks this output as Java Edition only.
Java 26.2
@p@p
/damage @p 4 minecraft:generic