Unable to use the /tag command to tag if wielding a specific item [duplicate]
Me and my friends have been creating a Minecraft realm, and I figured that I would make custom bosses and custom drops to spice up the game a bit.
I've just got to a weapon that I'm trying to cause wither in other players when it hits, but first to do that I'm trying to tag the wielder. I wrote the command
/tag @e[nbt={SelectedItem:{id:"minecraft:iron_sword",tag:{display:{Name:"Sword of Iapetos"}}}}] add IapetosSword
For some reason though, whenever I hold the sword, it doesn't tag me! I assume I wrote the code wrong, but I can't figure out where.
NBT checks must be exact and item names are JSON, not simple strings. So instead of …
"Sword of Iapetos"
… check for:
"{\"text\":\"Sword of Iapetos\"}"
Or alternatively:
'{"text":"Sword of Iapetos"}'
You can find out things like this easily by running this command:
/data get entity @s SelectedItem