News
Game
Guides
Downloads
Versions
/function
COMMANDS COMMAND BLOCKS & MAPS CHEATS · LEVEL 2 Added in 1.14 or earlier

/function command in Minecraft

/function runs every command of a .mcfunction file from a data pack, in order, with the same executor and position as the caller. It turns long command chains into readable files and can pass arguments to macro functions. A function tag runs several functions in one call.

Syntax

/function <name> [<arguments>|with]
ArgumentExpectsWhat it does
nameFunctionFunction or function tag ID, for example mypack:start or #minecraft:load.
argumentsoptionalNBT compoundCompound with the macro values, for example {name:"Alex",count:3}.
sourceoptionalBlock coordinates (x y z)Where the macro values come from: block coordinates, an entity or a storage ID, depending on the keyword.
pathoptionalNBT pathOptional NBT path inside the source; the compound found there becomes the macro arguments.
All 8 forms
  • /function <name>
  • /function <name> <arguments>
  • /function <name> with block <source>
  • /function <name> with block <source> <path>
  • /function <name> with entity <source>
  • /function <name> with entity <source> <path>
  • /function <name> with storage <source>
  • /function <name> with storage <source> <path>

Examples

Run a function

/function mypack:start

Runs every command of data/mypack/function/start.mcfunction once, in order.

Java 26.3

Pass a macro argument

/function mypack:greet {name:"Alex"}

In greet.mcfunction, the macro line $say Hello $(name) becomes say Hello Alex.

Java 26.3

Read arguments from a storage

/function mypack:greet with storage mypack:data player

Takes the macro values from the player compound of the mypack:data storage.

Java 26.3

Rerun the load functions

/function #minecraft:load

Runs every function in the minecraft:load tag, the ones that normally run after loading.

Java 26.3

Run a function for each player

/execute as @a at @s run function mypack:check

The function runs once per player, with @s and ~ ~ ~ pointing to that player.

Java 26.3
Build your command

Fill in the fields, then copy the command.

Command generator

Where functions live

A function is a text file at data/<namespace>/function/<name>.mcfunction inside a data pack, called as namespace:name. Write one command per line, without the leading slash; lines starting with # are comments. The function tags #minecraft:load and #minecraft:tick run their functions after loading and on every game tick. After editing a file, run /reload, and check with /datapack that the pack is enabled.

Macros and arguments

A line that starts with $ is a macro line: each $(key) is replaced before the command runs. Pass the values as a compound such as {name:"Alex"}, or read them from NBT with with entity, with block or with storage. A missing key stops the call with "Missing argument ... to function ...". Macro functions cannot be delayed with /schedule.

Tips

  • Wrap the call in /execute: execute as @a at @s run function mypack:check runs the file once per player.
  • /return ends a function early and gives it a value.
  • A single broken line keeps the whole file from loading, and the game then reports "Unknown function". The game log shows the faulty line.
  • Functions run at permission level 2 by default; servers change this with function-permission-level in server.properties.

✓ Checked in Java Edition 26.3 · updated 2 November 2026

/function: FAQ

Do commands in a function file start with a slash?

No, write each command without the slash. Lines starting with # are comments, and lines starting with $ are macro lines.

How do I run a function on every tick?

Add it to the minecraft:tick function tag, in the file data/minecraft/tags/function/tick.json of your pack. Keep it light, since it runs 20 times per second.

How do I use /function?

Type it in the chat with cheats on: /function <name> [<arguments>|with].

Who can use /function?

Cheats on, or operator level 2.

Related commands