This question already has an answer here:

I am making a dropper mini game on my Minecraft server and I am using a button to give a player the diamond. I need a command block that sees if they have a diamond already so they don't get two diamonds.

marked as duplicate by greg-449, Wondercricket, galacticninja, Joachim, Reflexive Jul 21 at 10:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Assume they don't have diamond at first by adding a tag by default:

/scoreboard players tag @a add d

If they do have a diamond, remove the tag:

/scoreboard players tag @a remove d {Inventory:[{id:minecraft:diamond}]}

Give players that have the "d" tag a diamond:

/give @a[tag=d] diamond

This can be done in just one command in Minecraft 1.13

/give @a[nbt=!{Inventory:[{id:"minecraft:diamond"}]}] diamond

You can run a clear command and then give them the diamond

/clear @p minecraft:diamond 1 0

/give @p minecraft:diamond 1 0 {display:{Name:"Optional Name"}}

Not the answer you're looking for? Browse other questions tagged or ask your own question.