Builds a simple player form with buttons that let the player take action.

Example

actionFormAskFavoriteMonth.ts

import { Player } from '@minecraft/server';
import { ActionFormData, ActionFormResponse } from '@minecraft/server-ui';

function askFavoriteMonth(player: Player) {
const form = new ActionFormData()
.title('Months')
.body('Choose your favorite month!')
.button('January')
.button('February')
.button('March')
.button('April')
.button('May');

form.show(player).then((response: ActionFormResponse) => {
if (response.selection === 3) {
player.sendMessage('I like April too!');
} else {
player.sendMessage('Nah, April is the best.');
}
});
}

Example

minigames.js

import { world } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";
const form = new ActionFormData();
form.title("Minigames");
form.body("Choose the games");
form.button("Spleef", "textures/items/diamond_shovel");
form.button("Murder Mystery", "textures/items/iron_sword");
form.button("Bedwars", "textures/minigames/bedwars.png");
for (const player of world.getAllPlayers()) {
form.show(player).then((response) => {
if (response.canceled) {
player.sendMessage("Canceled due to " + response.cancelationReason);
}
if (response.selection == 0) {
player.sendMessage("You have selected Spleef");
}
if (response.selection == 1) {
player.sendMessage("You have selected Murder Mystery");
}
if (response.selection == 2) {
player.sendMessage("You have selected Bedwars");
}
return;
}); // show player the form
}

Hierarchy

  • ActionFormData

Constructors

Methods

Constructors

Methods

  • Parameters

    • text: string | RawMessage
    • Optional iconPath: string
      Optional

    Returns ActionFormData

    Remarks

    Adds a button to this form with an icon from a resource pack.

  • Parameters

    • player: Player

      Player to show this dialog to.

    Returns Promise<ActionFormResponse>

    Remarks

    Creates and shows this modal popup form. Returns asynchronously when the player confirms or cancels the dialog.

    This function can't be called in read-only mode.

    Throws

    This function can throw errors.