Script API - v1.26.10
    Preparing search index...

    Class MessageBoxBeta

    A simple message form UI, 2 buttons and a text body.

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

    // Run /test:messagebox in the chat to see the message box in action
    system.beforeEvents.startup.subscribe((event) => {
    event.customCommandRegistry.registerCommand(
    {
    name: "test:messagebox",
    description: "Test the MessageBox API",
    permissionLevel: 0,
    },
    (origin) => {
    const player = origin.sourceEntity;
    if (!(player instanceof Player)) {
    return {
    message: "This command can only be used by a player.",
    status: CustomCommandStatus.Failure,
    };
    }
    MessageBox.create(player, "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) {
    console.log("Player chose to delete the item.");
    // Here you would add the logic to delete the item from the player's inventory
    }
    })
    .catch((e) => {
    console.error(e);
    });
    }
    );
    });
    Index

    Constructors

    Methods

    • Returns void

      Tell the client to close the message box. Throws FormCloseError if the message box is not open.

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

    • Returns boolean

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

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

    • Returns Promise<MessageBoxResult>

      Show this message box to the player. Will return a result even if the client was busy (i.e. in another menu). Will throw if the user disconnects.

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