Selectors pick which players or mobs a command affects. They work in almost every command that has a target argument.
| Selector | Selects |
|---|---|
@p | The nearest player. |
@r | A random player (Java: a random online player). |
@a | Every player. |
@e | Every entity, including mobs, items and players. |
@s | The entity running the command (you, in chat). |
@n | The nearest entity of any type (Java). |
Put arguments in square brackets, separated by commas: @e[type=cow,distance=..20].
| Argument | Meaning |
|---|---|
type=zombie | Only entities of this type; type=!player excludes players. |
name=Steve | Only entities with this name. |
distance=..10 | Within 10 blocks. Use ranges like 5..20. |
limit=3,sort=nearest | At most 3, nearest first. sort can be nearest, furthest, random or arbitrary. |
tag=boss | Only entities that have this tag (see /tag). |
scores={kills=5..} | Only entities whose score matches the range. |
team=red | Only members of this team. |
level=10.. | Players with experience level 10 or more. |
gamemode=survival | Players in this game mode. |
x=0,y=64,z=0,dx=10,dy=5,dz=10 | Inside a box from a corner. |
nbt={OnGround:1b} | Entities whose data matches. |
predicate=my:pack/test | Entities that pass a data pack predicate. |
/kill @e[type=item]Removes every dropped item in loaded chunks.
/tp @a @sTeleports every player to you.
/effect give @a[distance=..10] minecraft:regeneration 30 1Heals players within 10 blocks.
/give @r minecraft:diamond 3Gives three diamonds to a random player.