Skip to content

Posting to Discord

dxcufgb edited this page Oct 30, 2026 · 1 revision

Posting to Discord

The module writes the summary to the Data folder; a Discord bot on the same computer picks it up and posts it.

With the Foundry VTT Discord integration bot

The Foundry VTT Discord integration bot reads these files and posts the summaries; see its Session Summaries page.

Reading it from a bot (Node, discord.js)

For your own bot. The file layout is on The Files.

import { watch, readFileSync, existsSync } from "node:fs";
import path from "node:path";

const dir = path.join(process.env.LOCALAPPDATA, "FoundryVTT", "Data", "session-summaries");
const read = file => JSON.parse(readFileSync(path.join(dir, file), "utf8"));
const posted = new Set();
let timer = null;

watch(dir, (event, file) => {
  if (file !== "index.json" && file !== "latest.json") return;
  clearTimeout(timer);
  timer = setTimeout(async () => {          // wait for the write to finish
    // index.json is written last; latest.json only when there is no index.json
    const newest = existsSync(path.join(dir, "index.json")) ? read("index.json").sessions[0]?.json : "latest.json";
    if (!newest || newest !== path.basename(newest) || newest.startsWith(".")) return;   // bare file names only
    const summary = read(newest);
    if (summary.session.inProgress || posted.has(summary.session.id)) return;
    posted.add(summary.session.id);
    await channel.send(summary.markdown);   // or build an embed from the JSON
  }, 1000);
});

Clone this wiki locally