Developers Writing a plugin

Posting to Discord

A plugin can post by itself, for a milestone or an alert. The world's owner decides which channels get it, and can switch each kind of post off.

postToDiscord

Import it from "../relay/api.js" and call it whenever something worth posting happens:

import { world } from "@minecraft/server";
import { postToDiscord } from "../relay/api.js";

world.afterEvents.entityDie.subscribe(({ deadEntity }) => {
  if (deadEntity.typeId !== "minecraft:ender_dragon") return;
  postToDiscord({
    plugin: "dragon",
    kind: "dragon",
    embed: { title: "The Ender Dragon is dead!", color: 0x9b59b6 },
  });
});
FieldDescription
pluginYour plugin's id. With posts declared, the post goes only to the channels the owner chose for your plugin.
messageText. Discord markdown works.
embedAn embed, as in answers. Player heads work; drawn pictures don't yet.
authorThe name the post appears under.
kindOne of your postKinds, below.

On a dedicated server, posts made while BedrockRelay is reconnecting wait and go once it's back. On a Realm they go by way of our bot, so a post made while the bot isn't in the Realm is lost.

Where posts go

Declare posts in your definition, saying what your plugin posts, and pass your id as plugin:

export default {
  id: "dragon",
  name: "Dragon",
  version: "1.0.0",
  description: "Announces when the Ender Dragon dies.",
  posts: "When the Ender Dragon is killed.",
  commands: [],
};

The owner then picks the channels on the world's Plugins tab. Until they do, and while your plugin is switched off, its posts go nowhere. A channel can take plugin posts with no other events at all. Pack v0.4.0.

A post without plugin, or from a plugin that doesn't declare posts, goes to every channel with the Other addons event instead, like a script event. Declare posts: owners want to choose.

Kinds of post

If your plugin posts several kinds of thing, list them in postKinds so the owner can switch each off. Up to 25 of { id, name, default }:

  • id: lowercase letters, numbers, dashes and underscores. Pass it as the post's kind.
  • name: the switch's label on the dashboard.
  • default: false: starts switched off, for something only some owners want.
posts: "Risky things players do.",
postKinds: [
  { id: "tnt", name: "TNT placed" },
  { id: "diamonds", name: "Diamonds mined", default: false },
],

Every kind goes to the same channels. A post whose kind is switched off is dropped; one with no kind, or a kind you didn't declare, always goes. postKinds only counts alongside posts. Pack v0.4.2; older packs post every kind.

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

Read the help