Java 26.2
Enchant Command
Enchant
@p
/enchant @p minecraft:sharpness 5
Apply enchantments
The /enchant command validates its input: it refuses levels above the vanilla maximum, enchantments the held item cannot take, and pairs that conflict. That makes it the safe choice for survival-legal gear, and the wrong tool for Sharpness 1000 — which is written with /give instead.
Max legal Sharpness
/enchant @p minecraft:sharpness 5Level V is the vanilla cap -- the highest /enchant accepts on a held sword.
Efficiency on the held tool
/enchant @p minecraft:efficiency 5/enchant validates the target item -- it only applies to what the player is holding.
Mending for the whole team
/enchant @a minecraft:mending 1Selectors work like any command: @a enchants every player holding a compatible item.
/enchant validates its input and rejects any level above the vanilla maximum. For over-cap levels like Sharpness 1000 you must use /give with the enchantment written into the item instead — the generator points you to the Give tool for that.
/enchant only applies enchantments that are valid for the item the target is currently holding, and it refuses conflicting pairs (like Silk Touch with Fortune). Hold a compatible item, or use /give to force any combination.
Only the item in the main hand of the target selector. Switch the held item first, then run the command; it will not touch armor or off-hand items.
The vanilla cap for that enchantment — for example Sharpness V, Efficiency V, Protection IV. Anything higher is over-cap and needs /give.
Java 26.2
@p
/enchant @p minecraft:sharpness 5