Script API - v26.60
    Preparing search index...

    A simple message form with two buttons and a text body. Use this class to show a basic dialog to a player and handle the player's button selection.

    import { Player, system } from "@minecraft/server";
    import { DataDrivenScreenClosedReason, MessageBox } from "@minecraft/server-ui";

    // Run `/scriptevent example:demo` in chat to open the dialog.
    system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
    if (id !== "example:demo" || !(sourceEntity instanceof Player)) return;

    new MessageBox(sourceEntity, "Delete Item")
    .body("Are you sure you want to delete this item? This action cannot be undone.")
    .button1("Delete")
    .button2("Cancel", "Keep the item and close this dialog")
    .show()
    .then((response) => {
    if (response.selection === 0) {
    sourceEntity.sendMessage("Item deleted.");
    } else if (response.selection === 1) {
    sourceEntity.sendMessage("Canceled item deletion.");
    } else if (response.closeReason === DataDrivenScreenClosedReason.ServerClosed) {
    sourceEntity.sendMessage("The server closed the dialog.");
    }
    });
    });
    export class MessageBox {
    constructor(
    player: minecraftserver.Player,
    title: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    options?: MessageBoxOptions,
    );
    body(
    body: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    options?: MessageBoxBodyOptions,
    ): MessageBox;
    button1(
    label: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    tooltip?: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    ): MessageBox;
    button1WithOptions(
    label: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    options?: MessageBoxButtonOptions,
    ): MessageBox;
    button2(
    label: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    tooltip?: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    ): MessageBox;
    button2WithOptions(
    label: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    options?: MessageBoxButtonOptions,
    ): MessageBox;
    button3WithOptions(
    label: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    options?: MessageBoxButtonOptions,
    ): MessageBox;
    close(): void;
    isShowing(): boolean;
    show(): Promise<MessageBoxResult>;
    }
    Index
    • Parameters

      Returns MessageBox

      Sets the body text displayed in the message box. Returns the message box instance to allow method chaining.

      This function can't be called in restricted-execution mode.

      This function can throw errors.

      InvalidFormModificationError

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { MessageBox } from "@minecraft/server-ui";

      // Run `/scriptevent example:dangerwarning` in chat to open the prompt.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:dangerwarning" || !(sourceEntity instanceof Player)) return;

      const box = new MessageBox(sourceEntity, "Danger Warning");
      box.body("Entering the Nether will drop unprotected inventory items.");
      box.button1("Proceed");
      box.button2("Cancel");

      box.show().then((result) => {
      if (result.selection === 0) {
      sourceEntity.sendMessage("You chose to proceed.");
      } else {
      sourceEntity.sendMessage("You canceled the trip.");
      }
      });
      });
    • Parameters

      Returns MessageBox

      Sets the label for the first button of the message box. Returns the message box instance to allow method chaining.

      This function can't be called in restricted-execution mode.

      This function can throw errors.

      InvalidFormModificationError

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { MessageBox } from "@minecraft/server-ui";

      // Run `/scriptevent example:claimkit` in chat to open the prompt.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:claimkit" || !(sourceEntity instanceof Player)) return;

      const box = new MessageBox(sourceEntity, "Claim Kit");
      box.body("Claim your daily iron tools package now?");
      box.button1("Claim Now", "Puts items directly into your inventory");
      box.button2("Later");

      box.show().then((result) => {
      if (result.selection === 0) {
      sourceEntity.sendMessage("Claimed iron tools.");
      } else {
      sourceEntity.sendMessage("Postponed kit claim.");
      }
      });
      });
    • Parameters

      Returns MessageBox

      Sets the label and options for the first button of the message box. Returns the message box instance to allow method chaining.

      This function can't be called in restricted-execution mode.

      This function can throw errors.

      InvalidFormModificationError

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { MessageBox } from "@minecraft/server-ui";

      // Run `/scriptevent example:unlockskill` in chat to open the prompt.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:unlockskill" || !(sourceEntity instanceof Player)) return;

      const box = new MessageBox(sourceEntity, "Unlock Skill");
      box.body("Spend 10 skill points to unlock Fire Resistance?");
      box.button1WithOptions("Unlock", {
      tooltip: "Requires 10 skill points",
      imageDetails: { imagePackId: "core", imageSrc: "textures/items/fire_charge" },
      });
      box.button2("Cancel");

      box.show().then((result) => {
      if (result.selection === 0) {
      sourceEntity.sendMessage("Fire Resistance unlocked.");
      } else {
      sourceEntity.sendMessage("Skill unlock canceled.");
      }
      });
      });
    • Parameters

      Returns MessageBox

      Sets the label for the second button of the message box. Returns the message box instance to allow method chaining.

      This function can't be called in restricted-execution mode.

      This function can throw errors.

      InvalidFormModificationError

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { MessageBox } from "@minecraft/server-ui";

      // Run `/scriptevent example:discarditem` in chat to open the prompt.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:discarditem" || !(sourceEntity instanceof Player)) return;

      const box = new MessageBox(sourceEntity, "Discard Item");
      box.body("Are you sure you want to discard your selected item?");
      box.button1("Discard");
      box.button2("Keep Item", "Returns the item safely to your pack");

      box.show().then((result) => {
      if (result.selection === 1) {
      sourceEntity.sendMessage("Item kept safely.");
      } else {
      sourceEntity.sendMessage("Item discarded.");
      }
      });
      });
    • Parameters

      Returns MessageBox

      Sets the label and options for the second button of the message box. Returns the message box instance to allow method chaining.

      This function can't be called in restricted-execution mode.

      This function can throw errors.

      InvalidFormModificationError

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { MessageBox } from "@minecraft/server-ui";

      // Run `/scriptevent example:fasttravel` in chat to open the prompt.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:fasttravel" || !(sourceEntity instanceof Player)) return;

      const box = new MessageBox(sourceEntity, "Fast Travel");
      box.body("Fast travel costs 5 gold coins.");
      box.button1("Travel");
      box.button2WithOptions("Stay Here", {
      tooltip: "Cancel fast travel and keep coins",
      imageDetails: { imagePackId: "core", imageSrc: "textures/items/barrier" },
      });

      box.show().then((result) => {
      if (result.selection === 1) {
      sourceEntity.sendMessage("Fast travel canceled.");
      } else {
      sourceEntity.sendMessage("Fast traveling now.");
      }
      });
      });
    • Beta

      Parameters

      Returns MessageBox

      Sets the label and options for the third button of the message box. Returns the message box instance to allow method chaining.

      This function can't be called in restricted-execution mode.

      This function can throw errors.

      InvalidFormModificationError

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { MessageBox } from "@minecraft/server-ui";

      // Run `/scriptevent example:dungeongate` in chat to open the prompt.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:dungeongate" || !(sourceEntity instanceof Player)) return;

      const box = new MessageBox(sourceEntity, "Dungeon Gate");
      box.body("An iron gate blocks the corridor. How do you open it?");
      box.button1("Use Key");
      box.button2("Pick Lock");
      box.button3WithOptions("Turn Back", {
      tooltip: "Return to the dungeon entrance",
      });

      box.show().then((result) => {
      if (result.selection === 0) {
      sourceEntity.sendMessage("You unlocked the gate with a key.");
      } else if (result.selection === 1) {
      sourceEntity.sendMessage("You picked the lock.");
      } else if (result.selection === 2) {
      sourceEntity.sendMessage("You turned back to the entrance.");
      } else {
      sourceEntity.sendMessage("You closed the gate prompt.");
      }
      });
      });
    • Returns void

      Closes the message box if it is currently being shown to the player. Throws a FormVisibilityError if the form is not currently open.

      This function can't be called in restricted-execution mode.

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { DataDrivenScreenClosedReason, MessageBox } from "@minecraft/server-ui";

      // Run `/scriptevent example:matchready` in chat to open the prompt.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:matchready" || !(sourceEntity instanceof Player)) return;

      const box = new MessageBox(sourceEntity, "Match Ready");
      box.body("Starting arena match. Closes automatically in 3 seconds.");
      box.button1("Ready");
      box.show().then((result) => {
      if (result.selection === 0) {
      sourceEntity.sendMessage("You confirmed you are ready.");
      } else if (result.closeReason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the match prompt.");
      } else {
      sourceEntity.sendMessage("You closed the match prompt.");
      }
      });

      // Close the message box after 3 seconds (60 ticks).
      system.runTimeout(() => {
      if (box.isShowing()) {
      box.close();
      }
      }, 60);
      });
    • Returns boolean

      Returns true if the message box is currently being shown to the player, false otherwise.

      This function can't be called in restricted-execution mode.

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { DataDrivenScreenClosedReason, MessageBox } from "@minecraft/server-ui";

      // Run `/scriptevent example:weatheralert` in chat to open the prompt.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:weatheralert" || !(sourceEntity instanceof Player)) return;

      const box = new MessageBox(sourceEntity, "Weather Alert");
      box.body("Thunderstorm approaching the area.");
      box.button1("Acknowledge");
      box.show().then((result) => {
      if (result.selection === 0) {
      sourceEntity.sendMessage("You acknowledged the weather alert.");
      } else if (result.closeReason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the weather alert.");
      } else {
      sourceEntity.sendMessage("You closed the weather alert.");
      }
      });

      // Check whether the message box is still open before closing it.
      system.runTimeout(() => {
      if (box.isShowing()) {
      sourceEntity.sendMessage("Message box is still visible. Closing now.");
      box.close();
      }
      }, 60);
      });
    • Returns Promise<MessageBoxResult>

      Shows the message box to the player. Returns a promise that resolves with a MessageBoxResult containing the close reason and the player's button selection.

      This function can't be called in restricted-execution mode.

      This function can't be called in early-execution mode.

      import { Player, system } from "@minecraft/server";
      import { DataDrivenScreenClosedReason, MessageBox } from "@minecraft/server-ui";

      // Run `/scriptevent example:respawnbeacon` in chat to open the prompt.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:respawnbeacon" || !(sourceEntity instanceof Player)) return;

      const box = new MessageBox(sourceEntity, "Respawn Beacon");
      box.body("Do you want to set your spawn point here?");
      box.button1("Set Spawn");
      box.button2("Cancel");

      box.show().then((result) => {
      if (result.selection === 0) {
      sourceEntity.sendMessage("Spawn point set.");
      } else if (result.selection === 1) {
      sourceEntity.sendMessage("Spawn point unchanged.");
      } else if (result.closeReason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the beacon prompt.");
      } else {
      sourceEntity.sendMessage("You closed the beacon prompt.");
      }
      });
      });