Developers Writing a plugin

Your first plugin

A plugin is one JavaScript file that adds Discord commands to a Minecraft world. BedrockRelay does the Discord side; you write what happens in the game.

The file

A plugin default-exports a definition: who it is, and the Discord commands it adds, each with a run(). This one adds /health:

// health.js
import { findPlayer } from "../relay/api.js";

export default {
  id: "health",
  name: "Health",
  version: "1.0.0",
  description: "Check a player's health from Discord.",
  commands: [
    {
      name: "health",
      description: "Show a player's health",
      options: [{ name: "player", type: "player", description: "The player's name", required: true }],
      run({ player: name }) {
        const player = findPlayer(name);
        if (!player) return `**${name}** isn't online right now.`;
        const health = player.getComponent("minecraft:health");
        return { embed: { title: player.name, description: `❤ ${Math.ceil(health.currentValue)} / ${health.effectiveMax}` } };
      },
    },
  ],
};

Inside run() you have the whole Minecraft Script API, and a few helpers from ../relay/api.js. Whatever you return is the answer in Discord.

Trying it

You need a Bedrock Dedicated Server of your own with BedrockRelay installed (pack v0.3.0 or newer) and connected to a Discord server.

  1. Put health.js in development_behavior_packs/BedrockRelay/scripts/plugins/.
  2. Add its name, without .js, to the list in scripts/plugins/index.js in the same folder: export default ["health"];
  3. Restart the Minecraft server. The console shows [BedrockRelay] plugin loaded: Health 1.0.0. If it doesn't, see Testing.
  4. In a connected Discord server, run /health. The plugin is switched on the first time the world reports it, and at first only Discord administrators can use it.

Updating the BedrockRelay pack never touches your files in scripts/plugins/, and keeps your entries in index.js.

A Realm has no files you can reach, so plugins get there only through the dashboard. To try yours on a Realm, upload it as a private plugin. See Plugins on Realms first.

Where next

Running a Minecraft world rather than building for one? The help covers everything from setup to troubleshooting.

Read the help