Run Data Pack Functions with /function
The /function command lets you run custom scripts and function tags stored inside a data pack. You can execute a function directly or pass extra NBT data into it from the command line, a block, an entity, or command storage.
Players and mapmakers use this command to trigger groups of commands all at once without building long chains of command blocks. Note that you need Operator permissions (Level 2) or cheats enabled in single-player to run it.
/function <name> [<arguments>]/function <name> with block <source> [<path>]/function <name> with entity <source> [<path>]/function <name> with storage <source> [<path>]/function <name> [<arguments>]/function <name> with block <source> [<path>]/function <name> with entity <source> [<path>]/function <name> with storage <source> [<path>]| Argument | Type | What it means |
|---|---|---|
<name> | function | Specifies the function or #function tag from a data pack that you want to run. |
<arguments> | NBT compound | An optional NBT compound in curly braces, such as {NoAI:1b}, passed directly into the function. |
<source> | block position | Three coordinates x y z. Use ~ for relative or ^ for local coordinates. |
<path> | NBT path | An optional NBT path, like Inventory[0].id, that narrows down which part of the source data to send to the function. |
<source> | target selector one target | A player name, a UUID or a target selector such as @p, @a, @e or @s. |
<source> | resource ID | A namespaced ID such as minecraft:stone. |
/function custom:start_gameRuns a simple function named start_game from the custom data pack namespace without any extra arguments.
/function #adventure:reset_allExecutes every function listed inside the reset_all function tag.
/function arena:spawn_boss {NoAI:1b}Runs the spawn_boss function and passes an inline NBT compound setting NoAI to 1b.
/function tools:read_container with block 120 64 -45Executes the read_container function using all the NBT data from the block at coordinates 120 64 -45.
/function shop:check_slot with block ~ ~-1 ~ Items[0]Runs the check_slot function using only the NBT data from the first item slot of the block directly below the command execution point.
/function stats:inspect_player with entity @pExecutes the inspect_player function and passes the full NBT data of the nearest player.
/function quests:check_held_item with entity @s SelectedItemRuns the check_held_item function using the SelectedItem NBT path from the entity executing the command.
/function system:load_config with storage mypack:settingsRuns the load_config function using the root NBT data stored inside the mypack:settings storage ID.
/function minigame:apply_kit with storage server:kits ActiveKitExecutes the apply_kit function using only the NBT compound found at the ActiveKit path inside server:kits storage.
Measured from the game files of every Java release from 1.13 to 26.3.
+ /function <name> with block <source> [<path>]− /function <name> with block <sourcePos> [<path>]+ /function <name> [<arguments>]+ /function <name> with block <sourcePos> [<path>]+ /function <name> with entity <source> [<path>]+ /function <name> with storage <source> [<path>]− /function <name>Bedrock Edition also includes the /function command, but it only supports the basic syntax /function <name: filepath> and does not have the Java Edition options for passing NBT arguments from blocks, entities, or storage.
You need permission level 2, which means you must be an Operator on a multiplayer server or have cheats turned on in your single-player world.
The ability to pass inline NBT arguments or pull data using with block, with entity, and with storage was added in Java Edition 1.20.2.
No, the entity <source> argument only accepts one target at a time, so you must use a player name, a UUID, or a single-target selector like @p or @s.
/bossbar/data/execute/random/return/schedule/scoreboard/tag/team/trigger