1. Wiki
  2. /Commands
  3. /Commands basics

Commands basics

Learn how Minecraft Bedrock commands work: syntax, target selectors like @p and @e, selector arguments, and ~ and ^ coordinates.

Commands are short lines of text that make things happen in Minecraft: give items, teleport players, spawn mobs, change the weather and much more. They are also the easiest way to add logic to an add-on, because you can bundle them into functions.

The quick way: GodCraft

In GodCraft you write commands inside a Function, with hints that suggest command names and arguments as you type.

  1. Open the Workshop and add a Function to your add-on.
  2. Type your commands. The hints help you get the syntax right.
  3. Choose when it runs: every tick, once on world load, or only when you type /function.
  4. Export it together with the rest of your add-on.

The rest of this page teaches the command language itself, which you need either way.

Turn on cheats

Most commands only work when cheats are on.

  1. Open your world's settings.
  2. Turn on Activate Cheats (in the Game or Cheats section).
  3. Open chat and type /. A list of commands appears.

Achievements

Turning cheats on disables achievements for that world, even if you turn them off again later. Use a separate test world for add-on work.

A few commands, like /say and /tell, work without cheats.

Command syntax

Every command starts with its name, followed by arguments separated by spaces:

Chat
/give @p minecraft:diamond 5
  • give is the command.
  • @p is who gets the item (a target selector, see below).
  • minecraft:diamond is the item ID. For vanilla items you can leave out minecraft:.
  • 5 is the amount. It is optional: leave it out and you get 1.

Reference pages show required arguments and optional ones. For example, /give needs a player and an item, while the amount and data are optional. Every argument must be in the right order, and you cannot skip an optional one to set the one after it.

Tip

In chat, commands start with /. Inside function files and command blocks, the slash is optional and is usually left out.

Target selectors

A target selector picks which players or entities a command affects.

SelectorPicks
@pThe nearest player
@aAll players
@rA random player
@sYourself: the entity running the command
@eAll entities (mobs, items, players, and more)
@initiatorThe player who is talking to an NPC (used in NPC dialogue buttons)

You can also type a player's name instead of a selector, like /give Steve diamond. Names with spaces go in quotes: "Steve Two".

Selector arguments

Add arguments in square brackets to narrow the selection. Separate several with commas, and do not put spaces around =.

Chat
/kill @e[type=minecraft:zombie,r=10]

This removes only zombies within 10 blocks. The most useful arguments:

ArgumentMeaningExample
typeEntity type@e[type=minecraft:cow]
nameName or name tag@e[name=Bob]
familyType family of the mob@e[family=monster]
r and rmMaximum and minimum distance@a[r=20]
cHow many to pick, closest first@e[type=minecraft:pig,c=3]
tagHas a tag from /tag@a[tag=red_team]
mGame mode@a[m=survival]
l and lmMaximum and minimum XP level@a[lm=10]
x, y, zWhere to measure distance from@e[x=0,y=64,z=0,r=5]
scoresScoreboard values@a[scores={points=10..}]

Add ! to flip a test: @e[type=!minecraft:player] means "every entity that is not a player". A negative c picks the farthest instead of the closest.

Your own mobs work too. If you made myname:critter from Your first custom mob, try @e[type=myname:critter] or @e[family=critter].

Coordinates

Positions are written as three numbers: x (east and west), y (up and down) and z (south and north).

Absolute coordinates

Plain numbers are exact spots in the world:

Chat
/tp @s 100 70 -250

Relative coordinates: ~

A tilde ~ means "from where the command runs", measured along the world's axes. A number after it adds an offset.

Chat
/tp @s ~ ~10 ~
/setblock ~2 ~ ~ minecraft:gold_block
/summon minecraft:pig ~ ~1 ~
  • ~ ~10 ~ is 10 blocks straight up.
  • ~2 ~ ~ is 2 blocks east.
  • A lone ~ means "no change" on that axis.

See /teleport, /setblock and /summon.

Local coordinates: ^

A caret ^ is measured from where the entity is looking: left, up and forward.

Chat
/tp @s ^ ^ ^5

This moves you 5 blocks in the direction you face, even if you are looking diagonally. The three parts are ^left ^up ^forward, and negative numbers go the other way.

Note

You cannot mix ^ with ~ or plain numbers in one position. Use all three as ^ or none.

Running commands as others

/execute changes who runs a command and where. It is the most powerful command in the game:

Chat
/execute as @a at @s run summon minecraft:lightning_bolt ~ ~ ~

Read it from left to right: for every player (as @a), at their own position (at @s), run a summon. Inside /execute, @s means each selected entity in turn and ~ ~ ~ is their spot.

A few commands to try

Chat
/give @s minecraft:diamond_sword
/effect @a minecraft:speed 30 1
/time set day
/weather clear
/say Hello, world!
/kill @e[type=minecraft:item]
  • /effect gives Speed II for 30 seconds (amplifier 1 is level II).
  • /time and /weather change the world.
  • The last one clears all dropped items, which is handy when a test gets messy.

What next

Commands: Guides

We use cookies to improve your experience and analyse site traffic. Learn more