The player to show this message box to.
The title text to display at the top of the message box.
Optionaloptions: MessageBoxOptions
Optional configuration for the message box, such as the button layout.
The body text to display. Accepts either a plain string or an ObservableString.
Optionaloptions: MessageBoxBodyOptionsSets 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'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.");
}
});
});
The text label to display on the first button.
Optionaltooltip: string | ObservableString | ObservableUIRawMessage | UIRawMessage
Optional tooltip text shown when hovering over the first button.
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'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.");
}
});
});
The text label to display on the first button.
Optionaloptions: MessageBoxButtonOptions
Optional configuration for the first button, such as tooltip and image.
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'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.");
}
});
});
The text label to display on the second button.
Optionaltooltip: string | ObservableString | ObservableUIRawMessage | UIRawMessage
Optional tooltip text shown when hovering over the second button.
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'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.");
}
});
});
The text label to display on the second button.
Optionaloptions: MessageBoxButtonOptions
Optional configuration for the second button, such as tooltip and image.
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'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.");
}
});
});
Rc
The text label to display on the third button.
Optionaloptions: MessageBoxButtonOptions
Optional configuration for the third button, such as tooltip and image.
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'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.");
}
});
});
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);
});
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);
});
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.");
}
});
});
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.
Example: demo.ts
Source