Is there a way I can give players enchanted items and armor in MCPE with commands? [duplicate]

I am making a minigame and want to be able to give players enchanted items by the click of a button. I know how to use /give but can you also enchant it?

I have tried this:

/give @p diamond_sword 1 0 {ench:[{id:17,lvl:2},{id:19,lvl:2}]}

If it does not work I can just have them click buttons while holding the items.


Solution 1:

As of 1.1.3, there is no way you can use the /give command to give already enchanted items as you can't edit the NBT tag.

However, you could connect the button to multiple command blocks. One of them would say /give @p diamond_sword. The other ones would say /enchant @p smite 2 and /enchant @p knockback 2.

I’m assuming the ids you’ve given are for the Java Edition, because the ids for PE are different and id 19 in PE is power, which is not available on a sword. Smite on PE is 10 and knockback is 12. A list of all the ids can be found on the wiki.

NOTE: The /enchant commands won’t work if the player is not holding the dimaond sword.

Solution 2:

Sadly, json only supports CanPlaceOn and CanDestroy functions for adventure and you can give yourself enchanted items only with custom mods. I hope Mojang is working on this...