Skip to content

Instantly share code, notes, and snippets.

@nazt
Created May 4, 2026 08:40
Show Gist options
  • Select an option

  • Save nazt/e3a87a1570772f69eb86aaf8d388cdf7 to your computer and use it in GitHub Desktop.

Select an option

Save nazt/e3a87a1570772f69eb86aaf8d388cdf7 to your computer and use it in GitHub Desktop.
Discord Channel Reader — read history, sync context, multi-bot patterns (by Métis Oracle 🧮)

Discord Channel Reader

Read Discord channel history, download attachments, and sync context between bots.

Tools

fetch_messages(channel, limit)     — read history (max 100, oldest-first)
download_attachment(chat_id, mid)  — download files/images from a message
reply(chat_id, text)               — send message
react(chat_id, mid, emoji)         — add emoji reaction
edit_message(chat_id, mid, text)   — edit previous message

Read History

fetch_messages(channel="<channel_id>", limit=30)

Returns: [timestamp] user: content (id: message_id)

Attachments marked with +Natt. Use download_attachment to fetch.

Pagination (older messages)

Discord returns newest N messages. To go further back:

# Pseudo-code
last_id = None
while need_more:
    msgs = fetch_messages(channel, limit=100, before=last_id)
    last_id = msgs[0].id  # oldest in batch
    process(msgs)

Incoming vs History

Method When
<channel> tag (auto) Bot mentioned → realtime push
fetch_messages (manual) Pull history on demand

Multi-Bot Sync Pattern

When 2+ bots share a channel:

  1. Mention-based routing: @BotA triggers BotA only
  2. Last-read cursor: save last message_id processed in ψ/memory/
  3. Dedup: check message_id before processing
  4. Scope split: each bot owns a domain (pricing vs logistics)

Access Requirements

Bot needs these channel permissions:

  • View Channel
  • Send Messages
  • Read Message History
  • Attach Files

For private channels: bot must be explicitly added via Channel Permissions → Add members/roles.

Common Errors

Error Cause Fix
Missing Access Bot not in channel permissions Add bot role to channel
Intermittent Missing Access Permission cache expired Make channel private + add bot explicitly
Empty response No messages or wrong channel ID Verify channel ID from URL

Config

Bot token stored at: ~/.claude/channels/<oracle-name>/.env

Channel allowlist: ~/.claude/channels/<oracle-name>/access.json

{
  "groups": {
    "<channel_id>": { "requireMention": true, "allowFrom": ["<user_id>"] }
  }
}

Anti-Patterns

  • Don't poll in a loop — use fetch_messages on-demand
  • Don't store full message history in memory — save only decisions/facts
  • Don't reply to every message — only when mentioned or asked
  • Don't post pricing in public channels — check channel privacy first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment