🎪 Discord Showcase API

Public API serving messages from the #showcase channel in the Val Town Discord.

Architecture

Rendering mermaid diagram...

How it works:

  1. poll.ts runs every minute via Val Town's interval scheduler
  2. It fetches new messages from the Discord #showcase channel using the Discord API
  3. Messages are upserted into a SQLite database (so re-fetches don't create duplicates)
  4. api.ts is an HTTP endpoint that queries SQLite and returns JSON

API

GET /

Returns API info and total message count.

GET /messages

Returns showcase messages, newest first.

ParamTypeDefaultDescription
limitnumber50Messages per page (1–100)
offsetnumber0Pagination offset
searchstringSearch message content
authorstringFilter by author username

Example response:

{ "messages": [ { "id": "123456789", "author_id": "987654321", "author_username": "cool_dev", "author_avatar": "abc123", "content": "Check out my new val! ...", "timestamp": "2025-01-15T12:00:00.000Z", "attachments": [], "embeds": [...], "reactions": [{ "count": 5, "emoji": { "id": null, "name": "🔥" } }], "reply_to_id": null, "thread_id": null, "thread_name": null } ], "pagination": { "limit": 50, "offset": 0, "total": 1234, "has_more": true } }

Setup

  1. Create a Discord bot with Read Message History permission in the Val Town server
  2. Set the DISCORD_BOT_TOKEN environment variable to your bot token
  3. The poller will start collecting messages automatically

Files

FileTypeDescription
api.tsHTTPPublic JSON API
poll.tsIntervalFetches new messages every minute
discord.tsScriptDiscord API client
db.tsScriptSQLite schema & connection