Target selectors
Lots of commands ask "who?" — who gets the item, who gets teleported, who gets the effect. Target selectors are the shorthand that answers it, so you don't have to type player names.
Self
The entity running the command — you, when you type in chat. The one you’ll use most in functions.
Nearest player
The closest player to the command’s position.
All players
Every player. Great for world-wide effects and messages.
Random player
A random player — handy for minigames and raffles.
All entities
Every entity, not just players. Almost always paired with a filter like type=.
Narrow it down with arguments
Add [ ] after a selector to filter it. A few common ones:
- · type= — only a certain entity, e.g. @e[type=cow] (all cows).
- · r= / rm= — max / min radius, e.g. @a[r=10] (players within 10 blocks).
- · c= — count, e.g. @e[type=zombie,c=3] (the 3 nearest zombies).
- · name= — match a name, e.g. @e[name="Boss"].
- · tag= — match a scoreboard tag you’ve set.
effect @a[r=8] regeneration 10 1 Give Regeneration II to every player within 8 blocks.
Rule of thumb
In a function you'll usually want @s (the runner), @a (everyone), or @e with a type= filter. Reach for arguments whenever "all of them" is too broad.
See selectors in commands.
They show up everywhere — start with give and effect.
The /give command