Mcp

๐Ÿค– Discord.py ร— OMP Plugin Cheat Sheet

๐Ÿค– Discord.py ร— OMP Plugin Cheat Sheet

Bridge a discord.py bot (Python) with the OMP coding agent extension system (Bun/TS) โ€” from zero to full bidirectional integration.


๐Ÿง  Core Concept

OMP extensions = TypeScript/Bun. discord.py = Python. They’re separate runtimes. You bridge them via one of three tiers:

๐Ÿช Tier 1: Webhook ๐Ÿ”ง Tier 2: MCP Server ๐ŸŒ‰ Tier 3: Extension + Bot
Direction OMP โ†’ Discord only Both (LLM invokes tools) Both (event-driven)
Needs Python? โŒ No โœ… Yes โœ… Yes
Needs Bot Token? โŒ No (webhook URL) โœ… Yes โœ… Yes
Discord โ†’ OMP? โŒ โŒ โœ…
Auto-notify events? โœ… โŒ โœ…
LLM calls Discord? โŒ โœ… โœ…
Setup time ~5 min ~15 min ~30โ€“60 min
Deps None discord.py, mcp discord.py, aiohttp

โšก OMP Extension Contract (All Tiers)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// ~/.omp/agent/extensions/my-ext/index.ts
import type { ExtensionAPI } from "@oh-my-pi/pi-coding-agent";

export default function myExt(pi: ExtensionAPI) {
  // โ”€โ”€ Registration Phase (sync) โ”€โ”€
  pi.setLabel("My Extension");

  pi.on("agent_end", async (event, ctx) => { /* ... */ });
  pi.on("session_start", async (event, ctx) => { /* ... */ });

  pi.registerTool({ name: "my_tool", /* ... */ });
  pi.registerCommand("my-cmd", { /* ... */ });

  // โš ๏ธ CANNOT call pi.sendMessage() during load โ€” only in handlers
}

๐Ÿ“ก Key Lifecycle Events

1
2
3
session_start โ†’ input โ†’ agent_start โ†’ turn_start
  โ†’ tool_call โ†’ tool_execution_start โ†’ tool_execution_end โ†’ tool_result
  โ†’ turn_end โ†’ agent_end โ†’ session_shutdown
Event Use Case Return
agent_end “Done” notification to Discord โ€”
tool_call Audit / block dangerous ops { block, reason }
tool_result Redact secrets before logging { content }
session_start Init bot connection โ€”
session_shutdown Cleanup / final flush โ€”

๐Ÿช Tier 1 โ€” Webhook (Zero-Dep, 5 min)

No bot. No Python. Just fetch(). OMP โ†’ Discord one-way.