OniRelay SDK 1.1.0
https://hosting.oninetwork.com/developers/relay

Use named helpers for common game and Discord actions. Modules need basic JavaScript; these examples do not require packet names, command selectors or Minecraft API imports.

GET STARTED
1. Download the starter kit below, or open Community tools → Modules → Download starter examples. Start with Welcome on join.
2. For a ready example, upload its JSON package. To edit source, change manifest.json and index.js in its folder, then run node pack-module.mjs examples/friendly-welcome from the starter-kit folder. This writes an uploadable JSON file. Increase the manifest version when updating an existing module.
3. Upload in Modules, review the declared permissions, enable the module and open Settings & roles. Choose which Discord roles can run commands. The community owner can run them without a role assignment. Event handlers run for observed world events and do not use this command-role filter.
4. In Companion, download a fresh private BDS package and install it on your Bedrock Dedicated Server, preserving other packs. This expanded release supports BDS only. SDK 1.1 helpers require Companion 1.1. The public starter kit has no credentials and cannot connect a world by itself.
5. Check Companion status. Link your Minecraft account using /oni link in Discord and the private /onirelay:menu form in game. For player-targeted commands, that linked player must be online.
6. Run /oni module module:friendly-welcome command:welcome in Discord, or select the module from /onirelay:menu. Read /oni result job:<id> for the confirmed result. Rejoin to exercise the welcome event on your own test world.

This kit has no credentials. Download your private companion from your authenticated community workspace. Never publish that private package.

EXTERNAL API CLIENT
Use Node.js 20 or later on your own integration server. Keep ONIRELAY_API_KEY in its environment. Example:
import {createOniClient} from './client.mjs';
const oni = createOniClient({key: process.env.ONIRELAY_API_KEY});
console.log(await oni.status());
Methods: status(), players(), events(), modules(), invoke(module, command, args), job(id), claim(id), game.say(text, playerId?), discord.post(channelId, text, title?), rewards.claim(playerId, rewardId).
Each call uses one API request. There are no automatic retries. HTTP errors expose status, uncertain and retryAfter; inspect an uncertain write in Activity before repeating it. Game writes return queued jobs, not completed delivery. Player IDs come from players(), not Xbox XUIDs or Discord IDs. The invoking key can read only its own module/message jobs.

HELPERS
oni.game.tell(text) | game:message | Send a private message to the current online player; at most 1,500 characters.
oni.game.broadcast(text) | game:message | Send a world message to all players; at most 1,500 characters.
oni.game.title(title, subtitle?) | game:message | Show a title (200 characters) and optional subtitle (300) to the current player.
oni.game.actionBar(text) | game:message | Show up to 300 characters above the current player’s hotbar.
oni.game.players() | players:read | Return online player names in this world, excluding the assigned relay account.
oni.game.scores.get(name) | game:rewards | Read the current player’s score, or zero when no score exists.
oni.game.scores.set(name, value) | game:rewards | Set the current player’s integer score; create the objective when absent.
oni.game.scores.add(name, amount) | game:rewards | Add integer points to the current player and return the new total. Score writes are module logic, not a verified Discord-role reward.
oni.game.tags.has/add/remove(name) | game:rewards | Read, add or remove a current-player tag. Names use 1–40 letters, numbers, underscores or hyphens.
oni.discord.post(kind, text) | discord:post | Queue a module event for Channels routes that include module events. Returns an event ID, not a delivery confirmation. Mention-safe Discord embeds and plan post limits apply.
await oni.ui.choose({title, body, buttons}) | game:menu | Open a 1–20-button in-game menu. Returns a zero-based selection, or null if dismissed. Close chat if Minecraft reports a busy form.
oni.storage.get(key) | storage | Read a module-local JSON value, or null. Storage survives world restarts and is separate for each module ID.
oni.storage.set(key, value) | storage | Save a JSON value up to 8,192 serialized characters. Keys use 1–40 letters, numbers, underscores or hyphens.
oni.storage.remove(key) | storage | Remove one entry owned by this module.
oni.rewards.list() | game:rewards | List enabled reward IDs and names. This is not a claim that the current player is eligible.
await oni.rewards.claim(id) | game:rewards | Request a configured reward for the current player. The host verifies their linked Discord identity, current role and cooldown. Returns a claim receipt; delivery may still be queued.
oni.addons.command(name, args?) | game:addon_commands | Invoke an exact owner-reviewed namespaced add-on command in companion entity context. Engine acceptance does not confirm delayed effects.
await oni.markers.list({offset?}) | game:markers | Premium: read up to twenty markers owned by the current linked player and this module; follow next_offset for another bounded page.
await oni.markers.create({name, description?, type?, visibility?}) | game:markers | Premium: save the submitting player’s observed position. Returns the canonical marker ID and revision after host confirmation.
await oni.markers.update({id, version, name, description?, type?, visibility?}) | game:markers | Premium: edit a marker in this player/module namespace. Position stays unchanged. Community visibility also requires current owner publication consent.
await oni.markers.remove(id, version) | game:markers | Premium: remove only the current player’s marker in this module namespace, using its current revision.

EVENTS (declare the middle column in manifest.events)
onJoin | join | name; player helpers are available while that player remains online.
onLeave | leave | name; oni.player is null. Use a Discord post, storage or a world broadcast.
onDeath | death | name, cause, dimension, position and at; do not publish private coordinates without consent.
onChat | chat | name and text; only where the companion reports chat capability. Native Xbox chat does not automatically trigger companion handlers.
onMilestone | milestone | stat and value for observed playtime milestones.
onBlockBreak | block_break | block type ID; runs after the block was broken.
onBlockPlace | block_place | block type ID; runs after placement.

ERRORS
MODULE_INACTIVE | Check Companion status, enabled slots and the installed module revision; start a new action after reconnection.
PERMISSION_REQUIRED | Review the manifest permission, upload a new version if needed and explicitly enable it again.
PLAYER_OFFLINE | Link Discord, join the correct world and retry with that player online.
FORM_UNAVAILABLE | Close chat and other menus, then open the module again.
QUEUE_FULL | Check the connection and allow pending events to clear.
REQUEST_UNCONFIRMED | Read the returned explanation and claim history. Do not assume that an uncertain request failed or automatically repeat a reward.
INVALID_INPUT / STORAGE_INVALID | Check text, integer and storage limits; repair the affected stored entry if necessary.

BOUNDARIES
Keep api_version: 1 in the manifest. SDK 1.1 is an additive helper release, separate from UniqueShield’s version numbers. Existing commands, events and context.message/post/players/get/set remain supported.

Declare each event under its manifest name, such as events: ["join"]. defineModule accepts friendly onJoin-style handlers, or the existing events: {join} object. Commands and menu handlers receive (args, oni); event handlers receive (event, oni). Handler return values become command results; event return values are ignored.

A module handles one event at a time; extra events while its handler is busy are skipped. Keep handlers short. Gameplay events are observations, not a durable reward-delivery mechanism. Use Role rewards for one-time or cooldown item grants.

Helper permissions and module revision are checked on every call, including after awaiting a menu. After 30 seconds without fresh host authorization, helper calls stop until the companion reconnects. Source updates require reinstalling the companion; there is no automatic code injection into customer worlds.

Custom code remains trusted world code, not a security sandbox. Native Minecraft imports can access world scripting APIs. OniRelay does not execute uploaded JavaScript on the hosting server and does not expose raw network packets, Xbox tokens or an arbitrary-command helper through this SDK.

Commands called by a generic external API key have no linked in-game player. Use them for non-player module actions; player-specific role rewards use rewards.claim with the observed world player ID. An API key cannot impersonate a Discord member.
