链接子命令(as、at、if、unless…),为每个匹配的实体运行一条命令,支持 Java 与 Bedrock。
要在我的世界 Java 26.2 中向每位玩家发送一条个性化聊天消息,请运行: /execute as @a run tellraw @s "This message is sent to each of you." 命令链中的每个子命令从左到右逐步缩小最终命令的执行对象和执行位置。可选择一条生成的命令(例如 /tellraw)作为末尾命令,也可以自行输入任意命令。
每个子命令从左到右逐步缩小最终命令的执行对象和执行位置。
/execute as @a run tellraw @s "Hello from execute!"指令输出针对Java 26.2和Bedrock 1.26.40生成,并已于2026-07-10在游戏内完成粘贴验证。
Bedrock 1.26.40(自 1.19.50 起)支持与 Java 相同的 /execute 子命令链——实际差异在于条件和维度中的 id 形式,以及末尾命令的写法:
| 项目 | Java 26.2 | Bedrock 1.26.30 |
|---|---|---|
| 同一条命令链 | /execute as @a run tellraw @s "This message is sent to each of you." | /execute as @a run tellraw @s {"rawtext":[{"text":"This message is sent to each of you."}]} |
| 子命令 | as · at · positioned · facing · align · anchored · in · if · unless | 两个版本相同 |
| 维度 id(in …) | minecraft:overworld | overworld |
| 方块 id(if block …) | minecraft:diamond_block | diamond_block |
/execute 会在经过修改的上下文中运行另一条命令——以不同的实体身份、在某个位置,或仅在条件成立时执行。它是命令方块和数据包逻辑的核心。
子命令从左到右依次生效。“execute as @a at @s run …”会为每位玩家各运行一次最终命令,并定位到各自所在位置。加上 if/unless 可仅在某个方块、实体或分数匹配时才运行。
Bedrock 支持相同的子命令链接(as、at、positioned、if、unless…)。此处的目标使用 @p/@s/@a/@r 或玩家名称;“输入任意命令”选项可让你在两个版本上运行任意末尾命令。