All commands
๐Ÿ“œ
AdvancedJava โœ“Bedrock โœ“

/function

Run a list of commands stored in a datapack function file.

Overview

What is the /function command?

The /function command runs a function โ€” a saved list of commands stored in a datapack โ€” in one call. Functions are how you package and reuse complex command logic, call routines from other functions, and build large systems that would be impossible to type line by line.

They're the foundation of every datapack: tick loops, libraries and reusable behaviours all live in functions.

When to use it: Use /function to run a saved batch of commands from a datapack โ€” reusable routines, tick loops and libraries.

At a glance

Syntax

Syntax
/function <namespace:path>
commandtargetcoordsvaluerequiredoptional

See it

What it does

โœ“say Starting setupโ€ฆ
โœ“effect give @s speed 10
โœ“give @s diamond 64
โœ“tp @s ~ ~5 ~
โœ“say Ready!
Every stored command runs in order

Anatomy

Every part, explained

  1. 1
    /functionCommandRequired

    Runs a datapack function.

  2. 2
    <namespace:path>Function IDRequired

    The pack and path, like mypack:setup.

Your turn

Try it yourself

Playground
2 tokens ยท press Enter to run

Copy & paste

Examples

/function mypack:setup

Run the setup function.

/function mypack:loop

Trigger a loop function.

/function minecraft:tick

Call the built-in tick function.

Avoid these

Common mistakes

โœ•/function setup
โœ“/function mypack:setup

Always include the namespace before the colon.

โœ•/function mypack/setup
โœ“/function mypack:setup

Use a colon between pack and path.

Good to know

Frequently asked questions

How do you run a function in Minecraft?
Run /function <namespace>:<path>, e.g. /function mypack:setup, where the function file lives in a loaded datapack.
Where do function files go?
Inside a datapack under data/<namespace>/function/ (or .../functions/ in older versions), as .mcfunction files with one command per line.
How do you run a function every tick?
Add it to the #minecraft:tick function tag so it runs automatically 20 times per second.

Keep going

Related commands