Testfor specific held item with a certain name and lore?
Solution 1:
You are missing a closing curly bracket for the item data:
/testfor @p[r=10] {SelectedItemSlot:0,Inventory:[{Slot:0b,tag:{display:{Name:"Ticket",Lore:["This is a punched ticket."]}}}]}
However, I recommend using the SelectedItem
compound tag instead of checking for each individual hotbar slot. SelectedItem
will contain a copy of the player's currently-held item (minus the Slot
tag), such that you do not need to have multiple command blocks for each slot:
/execute if entity @p[distance=..10,nbt={SelectedItem:{tag:{display:{Name:"\"Ticket\"",Lore:["This is a punched ticket."]}}}}] run <command>