Custom commands
Concept
With scripts you can make your own slash commands such as /creator:hello. These commands can use the whole Script API and free-form logic, so they suit initialization and test tools, server administration commands and builder helpers. Registration is done with customCommandRegistry in system.beforeEvents.startup, and the name requires a namespace in the form namespace:commandname (Source: ms-learn, creator/Documents/scripting/custom-commands.md).
Registration example
import { system, world, CustomCommandParamType, CommandPermissionLevel, CustomCommandStatus } from "@minecraft/server";
system.beforeEvents.startup.subscribe((init) => {
init.customCommandRegistry.registerCommand(
{
name: "creator:hellocustomcommand",
description: "Celebration size",
permissionLevel: CommandPermissionLevel.GameDirectors,
optionalParameters: [{ type: CustomCommandParamType.Integer, name: "celebrationSize" }],
},
helloCustomCommand
);
});
function helloCustomCommand(origin, celebrationSize) {
// The callback is restricted execution. Defer world changes.
system.run(() => {
for (const player of world.getPlayers()) {
player.dimension.createExplosion(player.location, celebrationSize ?? 1);
}
});
return { status: CustomCommandStatus.Success, message: "Boom!" };
}
The fields of the registration definition are as follows.
| Field | Description |
|---|---|
name | Command name with a namespace |
description | Description shown in autocomplete |
permissionLevel | Permission level that can run it |
mandatoryParameters | Required parameters (front order) |
optionalParameters | Optional parameters (back order) |
Permission levels
The permission enum is named CommandPermissionLevel. The vanilla script metadata (@minecraft/server 2.11.0) defines Any, GameDirectors, Admin, Host and Owner under this name {vanilla}.
| Level | Meaning |
|---|---|
Any | Any player or environment can run it |
GameDirectors | Players with "Operator Commands" permission, and automation environments such as command blocks and scripts |
Admin | Only players with Operator permission. Cannot be used from automation (commands, scripts) |
Host | Only the game owner (host) |
Owner | Only from the dedicated server console |
Parameter types and enums
The callback is called as (origin, ...args), and if an optional parameter is omitted, undefined comes in.
| Parameter type | Value passed to the script |
|---|---|
BlockType | BlockType |
Boolean | boolean |
EntitySelector | Entity[] |
Float, Integer | number |
ItemType | ItemType |
Position | Vector3 |
PlayerSelector | Player[] |
String | string |
Register an enum first with registerEnum, and make the parameter name the same as the enum name.
system.beforeEvents.startup.subscribe((init) => {
const reg = init.customCommandRegistry;
reg.registerEnum("creator:my_enum", ["foo", "bar", "baz"]);
reg.registerCommand(
{
name: "creator:pick",
description: "Enum example",
permissionLevel: CommandPermissionLevel.Any,
mandatoryParameters: [{ type: CustomCommandParamType.Enum, name: "creator:my_enum" }],
},
(origin, choice) => ({ status: CustomCommandStatus.Success, message: `Picked: ${choice}` })
);
});
Community notes
Below are permission bugs, Realms limits and subcommand workarounds gathered from the community research.
Verification level marks follow the legend on the wiki home page. The basis of this page is community reports, and they may differ from the official Mojang documentation.
Custom commands
Registration and basic form
- History: Beta from Preview 1.21.80.22 through .9x, stable in 1.21.100 (@minecraft/server 2.1.0). On older versions you get
Could not find export 'CommandPermissionLevel'/'CustomCommandParamType'. Documentation:https://wiki.bedrock.dev/scripting/custom-commands,https://learn.microsoft.com/en-us/minecraft/creator/documents/scripting/custom-commands - Basic code:
import { system, CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus } from "@minecraft/server";
system.beforeEvents.startup.subscribe(({ customCommandRegistry }) => {
customCommandRegistry.registerEnum("wiki:mode", ["on", "off"]); // enum first
customCommandRegistry.registerCommand({
name: "wiki:goto", description: "...",
permissionLevel: CommandPermissionLevel.Any, // Any | GameDirectors | Admin | Host | Owner
cheatsRequired: false, // default is true -> disappears in worlds/Realms without cheats
mandatoryParameters: [{ name: "wiki:mode", type: CustomCommandParamType.Enum }],
optionalParameters: [{ name: "target", type: CustomCommandParamType.PlayerSelector }],
}, (origin, mode, targets) => {
system.run(() => origin.sourceEntity?.teleport({ x: 0, y: 80, z: 0 })); // writes go in system.run
return { status: CustomCommandStatus.Success, message: "ok" };
});
});
- Name: A namespace is required (
ns:cmd). If it does not collide with other packs or vanilla aliases, an alias without the prefix is generated automatically so it can also be typed as/cmd(on a collision the pack loaded first gets it and/ns:cmdis needed). The namespaced version cannot be hidden and can be hidden only by permission level. Use a unique prefix per pack (const name = n => \prefix:${n}``). If two packs register the same name, only one wins. - Registration time: Only in startup. Runtime registration (unlocking with a password and so on) is impossible. Changing parameters needs a full world restart, not
/reload(cannot change parameters ... during reload). Use inside function files works without/reload. - Callback signature:
(origin, ...args), with parameters coming in order (mandatory, then optional) as separate arguments (not an array or object). There is a report that when an alias is used, the command name is included in args.origin.sourceEntity(an Entity, undefined for the console and command blocks; check withinstanceof Player; do not compare with strings),origin.sourceType,origin.initiator,origin.sourceBlock. There is noorigin.player/origin.target. When run under/execute,sourceEntitybecomes theastarget, and when an NPC runs it,initiatoris the NPC. - Return value: Synchronously
{status: CustomCommandStatus.Success|Failure, message?}or undefined. An async callback (returning a Promise) is impossible, so usesystem.run(async () => ...)and return Success. For forms, attachform.show(...).then(...)and return right away, and report errors withsendMessage.messageis a string (no Error objects, use`${err.message}`), limited to 512 characters (a world crash was reported when exceeded), and%is a translation marker so escape it as%%(keys such as%gui.confirmwork but extra arguments are not possible). ReturningFailure(notFail) without a message gives an empty message (a bug). Using it together withsendMessageshows the message twice. In 26.70messageaccepts a RawMessage. - Execution: A custom command can also be run with
runCommand, butrunCommanddoes not return the command result text. Running a custom command closes the chat window, so it is a good time to show a form right after (the chat!prefixmethod has the chat window open and givesUserBusy). - Wrappers/tools:
command-wrapper(npm, github.com/Aevarkan/command-wrapper;defineParameter,defineCommand,new CommandRegister("prefix", CommandPermissionLevel.GameDirectors, true); enums withas const; bundling needed, guidehttps://wiki.aevarkan.dev/dev/mc-bundling), aCustomCommandclass that bundles registration into one startup callback (a type wrapperCustomCommand.register({ ..., addSystemRunBeforeExecution, parameters, callback }): typed parameter arguments, automatic enum registration,data.getArgument, an option to run the callback outside restricted execution; not a verified library), a GUI builderhttps://leowascoding.github.io/studio/html/custom-commands.html, Shulker Commands 1.0.0 (https://github.com/Duskaraa/shulker-commands, MIT, stable APIs only; you describe each command's name, permission, parameters and handler in one object, and it registers enums, subcommands, permissions and a help command and checks game limits before load. A builder page that generates the code is athttps://duskaraa.github.io/shulker-commands/.{single report})
Parameters
- Types:
String, theIntegerandFloatfamily,Boolean,Enum,PlayerSelector,EntitySelector, position and so on.PlayerSelectorisPlayer[](can be an empty array;JSON.stringifygives only{id,typeId}). Enum values arrive as strings. There is a report that one command is limited to 8 parameters{single report}. - enum:
registerEnum("ns:name", [...])must come before the command, and the parameternamemust exactly equal the enum name (including the namespace) (there are both reports that anenumNamefield exists and reports that it does not,{conflict}; the sure method is paramname= enum name, so enum names must be unique across commands). Enum names must have a namespace. - Missing features: Subcommands/overloads/conditional parameters (an optional argument only for a specific enum value), hiding aliases, mixed (number|string), any and command types, rest-of-string (greedy) arguments. A String is one token (quotes if it contains spaces), and quotes are also needed when putting a number in a String. Workarounds: chaining N optional String arguments, separating with
_and thensplit, taking a String and parsing it yourself (handle~/~Nrelative coordinates yourself), separate commands,!prefixchat commands. Mojang: "the parser is fragile", no schedule. Vanilla command behavior cannot be redefined (only permissions). (One reporter's claim that "subcommands are possible with enums" is{unverified}) execute in <dim>:CommandOriginhas no dimension, so it cannot receive theexecute incontext (useorigin.sourceEntity?.dimension/sourceBlockor a dimension argument).execute as/at/positionedwork.
Permission problems
- MCPE-230568: When a non-OP uses a command that has a selector parameter (PlayerSelector/EntitySelector), even typing a player name directly gives
<insufficient permissions for selector expansion>(even withpermissionLevel: Any). Unresolved from 2025-11 through after 2026-05. Workaround: take the name as a String parameter and look it up yourself, or handle permissions in the script. There is also a report that aPlayerSelector+ Integer combination worked only after changing tocheatsRequired: false.{community confirmed} - OP on Realms/servers maps to GameDirectors:
CommandPermissionLevel.Adminor higher does not work or is hidden even for the Realm owner and OPs (it also failed on Aternos withAdmin+cheatsRequired:true). UseGameDirectors, but since command blocks can also run it, check the origin. Do an extra check with tags when running. - Command versus
scriptevent:/scripteventdoes not consume a command name, is hidden from users and changes without reloading, so it suits calls within a pack or between packs. Custom commands work on Realms (more portable than the betachatSend). - Other: Scripts cannot run high-permission commands such as
op(to prevent backdoors).player.commandPermissionLevelis writable (lowering toAnyremoves access to OP commands, but the badge remains), anddeopis impossible./transferalso works in ordinary worlds but needs a permission higher than host. Script commands run at the GameDirectors level and/connectcannot be run. Education'seducation.jsonhides commands for all players, so gate teacher features with custom commands. - Troubleshooting: If a new command does not show, the pack was not applied to the world or is in a wrong folder (isolated build). There is a case where it worked only after calling it once in the namespaced form (suspected bug).
| id | Source | License | Commit | Accessed |
|---|---|---|---|---|
private-research | Private research (-) | - | 2026-11-13 | |
ms-learn | Minecraft Creator documentation (Microsoft Learn) | CC BY 4.0 (documentation), MIT (code) | a9fd1c0 | 2026-11-13 |
bedrock-wiki | Bedrock Wiki | CC BY 4.0 (docs/licenses/CC-BY-4.0.md in the repository) | 0930b39 | 2026-11-13 |