Create a Plugin
Scaffold, build, and run your first plugin.
1. Scaffold It
bun create github.com/Sharkord/plugin-example my-pluginThat gives you a working plugin: a slash command, a server action called from a React component, a setting, an event listener, persistent storage, and a server-to-client push.
my-plugin/
manifest.json identity and target SDK version
build.ts builds, and copies into your server if configured
publish.ts releases on GitHub and opens the marketplace PR
scripts/setup.ts clones and links the SDK and builder into .repos/
src/types.ts the contract both halves share
src/server/index.ts runs in the Sharkord server process
src/client/index.ts declares which components render where
src/client/home.tsx a componentThe SDK, UI package and builder are not on npm yet. bun create runs bun run setup, which clones Sharkord and plugin-builder into .repos/ and bun links them. Run it again to update them.
2. Fill In the Manifest
{
"id": "my-plugin",
"name": "My Plugin",
"author": "Me",
"description": "Does something useful.",
"homepage": "https://example.com",
"logo": "https://example.com/logo.png",
"sdkVersion": 2,
"version": "0.0.1"
}id: lowercase letters, numbers and dashes, up to 64 characters. Must match the folder the plugin is installed into.sdkVersionandversionare overwritten on every build: the SDK version from the linked SDK, the version frompackage.json. Bumppackage.json, not the manifest.homepageandlogoare optional URLs.
3. Declare the Contract
One type describes what your plugin exposes, and both halves import it. See Contract.
// src/types.ts
type TPlugin = {
actions: { roll: { payload: { sides: number }; response: number } };
commands: { roll: { args: { sides: number }; response: string } };
};
export type { TPlugin };4. Write the Server Half
// src/server/index.ts
import type { PluginContext, UnloadPluginContext } from "@sharkord/plugin-sdk";
import type { TPlugin } from "../types";
const onLoad = async (ctx: PluginContext<TPlugin>) => {
ctx.logger.log("my-plugin loaded");
const settings = await ctx.settings.register([
{
key: "maxSides",
name: "Maximum sides",
type: "number",
defaultValue: 20,
},
] as const);
const roll = (sides: number) =>
1 + Math.floor(Math.random() * Math.min(sides, settings.get("maxSides")));
ctx.commands.register({
name: "roll",
description: "Rolls a die.",
args: [{ name: "sides", type: "number", required: true }],
executes: async (invoker, args) => `You rolled ${roll(args.sides)}.`,
});
ctx.actions.register({
name: "roll",
executes: async (invoker, payload) => roll(payload.sides),
});
};
const onUnload = async (ctx: UnloadPluginContext) => {
ctx.logger.log("my-plugin unloaded");
};
export { onLoad, onUnload };Anything you need to keep on disk goes in ctx.dataPath, not ctx.path: installing an update deletes and rewrites the plugin folder, while the data folder survives updates and is removed with the plugin.
Start with one command or one action. Once it loads cleanly, add settings, UI, hooks, or voice.
5. Build
Set SHARKORD_PLUGINS_PATH in .env:
# development server
SHARKORD_PLUGINS_PATH=<sharkord repo>/apps/server/data/plugins
# installed server
SHARKORD_PLUGINS_PATH=~/.config/sharkord/pluginsbun run builddist/ is wiped and gets:
| Path | What it is |
|---|---|
dist/<plugin-id>/ | The plugin, copied into SHARKORD_PLUGINS_PATH when set |
dist/<plugin-id>-<version>.tar.gz | The release archive |
dist/<version>.json | The registry version file, with checksum and size |
A new plugin folder shows up in the server settings without a restart. Enable plugins there, then enable yours. Restart the server to pick up a rebuild, since the server caches the loaded module.
6. Publish
See Marketplace.
Things That Will Bite You
ctx.pathis deleted on every update. Usectx.dataPath.- Toggling a plugin does not reload rebuilt code. Restart the server.
- Tailwind classes mostly do not work. Sharkord compiles Tailwind from its own sources, so a class no Sharkord file uses is not in the stylesheet. Use inline styles with the host's CSS variables (
var(--foreground),var(--primary),var(--radius)) so your UI follows the user's theme. - Keep
as conston your settings definitions, orsettings.getloses the type of what it returns. bun tsc --noEmitreports errors from the linked SDK packages, not from your code. Yours are the ones undersrc/.
Next
- Commands and Actions for behavior
- Components and Client SDK for UI
- Marketplace to publish it