How to detect if a player has no item selected in his hand?

So, in version 1.12 we can easily detect if a player has nothing selected in his hand by just using the nbt {SelectedItem:{}}.

I realise that it is no longer working in version 1.13 +. I tried to replace it with {nbt=SelectedItem:{id:“”}}, but it does not work. Does anyone know how to solve it? I'm currently working on an Antman function datapack, I really need that command to make it functionable.


You can use nbt in your target selector in 1.13+. The SelectedItem tag will not be present in a player who doesn't have a selected item.

This command would teleport every player holding an item to your position:

/tp @a[nbt={SelectedItem:{}}] ~ ~ ~

To teleport them to your position when they don't hold an item you can use a ! to negate the result, basically telling you if the player does not have a selected item:

/tp @a[nbt=!{SelectedItem:{}}] ~ ~ ~