Since a lot of people are asking this, i thought this might help.
To give enchanted items through command blocks, you must place the activator and connect it to 2 command blocks. On one of the command blocks, set it back by 1 with a redstone repeater and type in the set-back one "Enchant @p [Enchantment ID] [Level]". Then, in the one without the repeater, type /give @p [Item that is going to be enchanted] [Amount]. Then, you're done!
A video tutorial - (Please support my channel by subscribing :D)
If the player's already holding something, this won't work. (or if their cursor isn't over the slot the item will go into)
The player currently is holding a wooden sword. You give them a diamond sword, and enchant the item they are holding. The wooden sword gets the enchantment, not the diamond sword.
The player's cursor is on their 9th slot in the hotbar. You give the player a diamond sword, it goes into their 1st slot on their hotbar. The command block enchants the item they are holding, which is nothing. Nothing gets the enchantment, the diamond sword remains unenchanted.
Proof of concept, perhaps. But nothing complete, by far.
Clear player's inventory, give them 9 diamond swords, enchant the item, clear all diamond swords that do not have the enchantment.
I cant get the /enchant thing to work for multiplayer, i have the item in my hand (e.g. bow)
and when i click the lever it doesnt do anything, this is whats written into my command block:
enchant @p 48 2