The execute command
execute does nothing by itself. Its job is to change the context another command runs in: who runs it, where from, and whether it runs at all
The shape of the command
Every execute ends with run followed by the command you actually want. Everything between execute and run adjusts the context, and you can stack as many parts as you like
execute as @a at @s run say สวัสดี
as @a— changes *who* runs it — here every player, one at a timeat @s— changes *where* it runs from — the position of whoever is currently running itrun say สวัสดี— the real command that fires
The difference between as and at
This is the single most confusing part. The two look alike but change different things, and they really are independent
| Keyword | What it changes | Affects |
|---|---|---|
as |
The identity of the runner | What @s means in the command that follows |
at |
The position and rotation it runs from | What ~ and ^ mean in the command that follows |
Using as without at is the most common mistake: the identity changed but the position is still the command block’s, so ~ ~ ~ lands at the block rather than at the player. A simple rule — if you used as and the command contains ~, follow it with at @s
Order matters
The context parts are read left to right, each working on the context the previous one produced. Swap them and the result genuinely changes
-
execute as @a at @s run ...— pick each player, then move the position to them — the command runs at each player -
execute at @a as @s run ...— move the position to each player, but the identity is unchanged — a different result
The form you want almost every time is as first, at second
Conditions with if and unless
if runs when the condition holds, unless runs when it does not. You can stack several, and every one must pass before the command fires
| Condition | Checks |
|---|---|
if block | Whether the block at a position is a given type |
if entity | Whether any entity matches a target selector |
if score | Whether a scoreboard score meets a requirement |
The most common use is checking what a player is standing on — the way to build an invisible pressure plate
execute as @a at @s if block ~ ~-1 ~ minecraft:gold_block run effect give @s minecraft:jump_boost 5 1
Note that ~-1 is one block below the feet — the block being stood on. ~ ~ ~ would be the player’s own position
When to use positioned
positioned moves the anchor to a set of coordinates. Where at moves you to an entity, positioned moves you to a position
- Use it when a command should act at a spot with no entity there
- It stacks with at — at @s positioned ~ ~5 ~ is five blocks above the player
Common problems
| Symptom | Cause |
|---|---|
| It runs but the effect lands at the command block | You used as but forgot at @s |
| Complete silence, no error | The if condition simply did not hold, which is not an error |
| It turns red near the end | The word run before the real command is missing |
| @s at the end matches nobody | There was no as, so @s is still the command block, which is not a player |
Related tools
Other guides to read next
- Minecraft command basics — Start from zero: how to enable cheats, where commands can be typed, and enough about selectors and coordinates to get going
- Target selectors in depth — A deep look at the square-bracket arguments, from type and distance through limit and sort, plus how to work out why a command matched nobody
- Coordinates: numbers, ~, and ^ — Why ~ and ^ cannot be mixed, why blocks end up in the wrong place, and which form to reach for in which situation
- Command blocks — Take the commands you generated and run them automatically — once, on repeat, or chained one after another
- Why an old give command stops working — Legacy NBT, 1.20.5 components, and 1.21.5 components side by side — compared using commands built by the generator itself
- Scoreboard basics — Create an objective the game tracks for you — or track it yourself from a command block — then use the score as a condition elsewhere
- My command does not work — Work back from the error the game shows you, with the usual cause behind each one