Skip to content

@minecraft/server-ui


@minecraft/server-ui / MessageBox

Class: MessageBox

Defined in: @minecraft/server-ui/index.d.ts:674

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.

Constructors

Constructor

new MessageBox(player, title): MessageBox

Defined in: @minecraft/server-ui/index.d.ts:688

Parameters

player

Player

The player to show this message box to.

title

string | ObservableString | ObservableUIRawMessage | UIRawMessage

The title text to display at the top of the message box.

Returns

MessageBox

Remarks

Creates a new MessageBox for the specified player with the given title.

Throws

This function can throw errors.

minecraftserver.InvalidEntityError

Methods

body()

body(body): MessageBox

Defined in: @minecraft/server-ui/index.d.ts:706

Parameters

body

string | ObservableString | ObservableUIRawMessage | UIRawMessage

The body text to display. Accepts either a plain string or an ObservableString.

Returns

MessageBox

Remarks

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.

Throws

This function can throw errors.

InvalidFormModificationError


button1()

button1(label, tooltip?): MessageBox

Defined in: @minecraft/server-ui/index.d.ts:723

Parameters

label

string | ObservableString | ObservableUIRawMessage | UIRawMessage

The text label to display on the first button.

tooltip?

string | ObservableString | ObservableUIRawMessage | UIRawMessage

Optional tooltip text shown when hovering over the first button.

Returns

MessageBox

Remarks

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.

Throws

This function can throw errors.

InvalidFormModificationError


button2()

button2(label, tooltip?): MessageBox

Defined in: @minecraft/server-ui/index.d.ts:743

Parameters

label

string | ObservableString | ObservableUIRawMessage | UIRawMessage

The text label to display on the second button.

tooltip?

string | ObservableString | ObservableUIRawMessage | UIRawMessage

Optional tooltip text shown when hovering over the second button.

Returns

MessageBox

Remarks

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.

Throws

This function can throw errors.

InvalidFormModificationError


close()

close(): void

Defined in: @minecraft/server-ui/index.d.ts:763

Returns

void

Remarks

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.

Throws

This function can throw errors.

minecraftcommon.EngineError

FormVisibilityError

minecraftserver.InvalidEntityError


isShowing()

isShowing(): boolean

Defined in: @minecraft/server-ui/index.d.ts:772

Returns

boolean

Remarks

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.


show()

show(): Promise<MessageBoxResult>

Defined in: @minecraft/server-ui/index.d.ts:789

Returns

Promise<MessageBoxResult>

Remarks

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.

Throws

This function can throw errors.

minecraftcommon.EngineError

FormVisibilityError

minecraftserver.InvalidEntityError