Skip to content
WikilyWIKILY
All games23 Wikis · pick your game
Commands and cheatsTarget selectors

Switch game

23 Wikis · pick your game
Target Selectors

Command reference

Target Selectors

A target selector picks the players or entities a command acts on. It starts with @ and a letter and can be narrowed down with filters in square brackets.

Details

Selectors@p, @a, @r, @s, @e, @n
Selector arguments21
Filter syntax@e[name=value,name=value]. Spaces around = and , are allowed. All filters must match.
NegationPut ! before the value, for example type=!minecraft:player. Works for name, gamemode, team, type, tag, nbt and predicate.
Ranges5 (exactly), 3.. (at least), ..10 (at most), 3..10 (between). The smaller number comes first.
Other targetsA player name (up to 16 characters) or an entity UUID can be typed instead of a selector.
Removed entities@e and @n skip entities that have died or been removed. Every other entity counts, including items, arrows and minecarts.
Search areaNormally every dimension is searched. Using distance, x, y, z, dx, dy or dz limits the search to the dimension the command runs in.
One target onlyCommands that take a single target refuse a selector that could return more. Add limit=1 to @a or @e to use it there.
Players onlyCommands that take players refuse @e and @n unless the selector is limited to players, for example with type=minecraft:player.
PermissionSelectors need permission to use. Without it the game answers "Selector not allowed".

Selectors

@pThe nearest playerNearest first1/tp @p 0 64 0
@aAll playersNo fixed orderNone/gamemode creative @a
@rA random playerRandom1/give @r minecraft:diamond 1
@sThe entity running the commandNot used1/tp @s ~ ~10 ~
@eAll entities that are aliveNo fixed orderNone/kill @e[type=minecraft:arrow]
@nThe nearest entity that is aliveNearest first1/damage @n[type=minecraft:pig] 2

Selector arguments

nameEntities with this nameText, in quotes if it has spaces. Once, or several times with !/effect give @a[name=!Steve,name=!Alex] minecraft:speed 30
distanceDistance from the command position in blocksNumber or range, not negative. Once/kill @e[type=minecraft:zombie,distance=..10]
levelPlayers by experience levelWhole number or range, not negative. Once. Players only/xp add @a[level=30..] 1 levels
xMoves the point distance and the box are measured fromNumber. Once/kill @e[x=0,y=64,z=0,distance=..5]
yMoves the point distance and the box are measured fromNumber. Once/kill @e[x=0,y=64,z=0,distance=..5]
zMoves the point distance and the box are measured fromNumber. Once/kill @e[x=0,y=64,z=0,distance=..5]
dxEntities touching a box that reaches this far along xNumber, may be negative. Once. dy and dz count as 0 if left out/kill @e[x=0,y=64,z=0,dx=10,dy=5,dz=10]
dyEntities touching a box that reaches this far along yNumber, may be negative. Once/kill @e[x=0,y=64,z=0,dx=10,dy=5,dz=10]
dzEntities touching a box that reaches this far along zNumber, may be negative. Once/kill @e[x=0,y=64,z=0,dx=10,dy=5,dz=10]
x_rotationUp and down view angle (pitch)Number or range in degrees. Once/tp @a[x_rotation=-90..-45] ~ ~1 ~
y_rotationLeft and right view angle (yaw)Number or range in degrees. Once/tp @a[y_rotation=-45..45] ~ ~1 ~
limitKeeps only the first so many resultsWhole number, at least 1. Once. Not on @s/kill @e[type=minecraft:item,limit=5]
sortOrder of the results before limit is appliednearest, furthest, random or arbitrary. Once. Not on @s/kill @e[type=minecraft:cow,sort=furthest,limit=2]
gamemodePlayers by game modesurvival, creative, adventure or spectator. Once, or several times with !. Players only/gamemode survival @a[gamemode=!survival,gamemode=!adventure]
teamEntities on this teamTeam name. Empty means no team, ! alone means any team. Once, or several times with !/tellraw @a[team=!red,team=!blue] "x"
typeEntities of this type or type tagEntity id, or a tag with #. Once, or several times with ! or with tags/kill @e[type=!minecraft:player,type=!minecraft:villager]
tagEntities that carry this tagTag name. Empty means no tags, ! alone means any tag. May repeat/kill @e[tag=marked,tag=!safe]
nbtEntities whose data contains these valuesData in { }. May repeat, ! allowed/kill @e[type=minecraft:zombie,nbt={NoAI:1b}]
scoresEntities by scoreboard score{objective=range,...}. Every listed score must be set and match. Once/tellraw @a[scores={kills=10..,deaths=..3}] "x"
advancementsPlayers by advancement progress{id=true or false}, or {id={criterion=true}}. Once. Players only/tellraw @a[advancements={minecraft:story/mine_stone=true}] "x"
predicateEntities that pass a data pack predicatePredicate id. May repeat, ! allowed/kill @e[predicate=my_pack:is_wet]

Repeating and negating

name, gamemode, team, typeOne plain value, or any number of ! values. A plain value cannot follow a ! value
type with a tagSeveral tags may be listed, each one once, as long as no plain type was given
tag, nbt, predicateMay be used any number of times, with or without !
distance, level, x, y, z, dx, dy, dz, x_rotation, y_rotation, limit, sort, scores, advancementsOnly once per selector
limit, sortCannot be used on @s

Targets without a selector

Player nameThe online player with that name/kill Steve
UUIDThe entity with that unique id/kill dd12be42-52a9-4a91-a8a1-11c01849e498

Examples

/kill @e[type=minecraft:zombie,distance=..10]

Kills every zombie within 10 blocks.

/give @a[gamemode=survival,distance=..20] minecraft:bread 3

Gives 3 bread to every survival player within 20 blocks.

/tp @e[type=minecraft:villager,sort=nearest,limit=3] @s

Teleports the three nearest villagers to you.

/kill @e[type=minecraft:item,nbt={Item:{id:"minecraft:diamond"}}]

Removes dropped diamonds.

/tellraw @a[scores={kills=10..},team=!red] {text:"Well done",color:"green"}

Sends a message to players with at least 10 kills who are not on team red.

/kill @e[type=#minecraft:skeletons]

Kills every entity in the skeletons type tag.

/execute as @a at @s run tp @s ~ ~1 ~

Moves every player up one block from where they stand.

Join the creator communityThe people who build the Minecraft Java Edition wiki are on our Discord. Ask questions or suggest pages.Join Discord (opens Discord in a new tab)