Java — /itemSwitch edition using the selector in the header.
Quick templates
Target
Entity selector
Slot
Action
Item ID
Count
/item entity @s weapon.mainhand replace minecraft:diamond_sword 1Quick templates
Target
/item entity @s weapon.mainhand replace minecraft:diamond_sword 1