Skip to content

api.treasury

The campaign's Treasury — its buckets, the items, the running distribution session — as the user sees it.

Part of the Action API · Function reference · Since Action API 0.5 (v0.103.0)

Signature

api.treasury.buckets(): Promise<TreasuryBucket[]>
api.treasury.holdings(characterId?: string): Promise<TreasuryItem[]>
api.treasury.distribution(): Promise<Record<string, unknown> | null>

Asynchronous — await each.

Returns

buckets() — every bucket the user may see: { id, name, kind, revealed, carriedBy, characterId, tokenId }, kind one of party, hoard, merchant, starting, loot. A member sees the party's bucket, the revealed ones, and loot the campaign's settings show them; the GM sees all.

holdings(characterId?) — the items the Treasury view carries, each { id, name, holderType, holderId, earmarkedCharacterId, quantity, marketValue, price, category }. With a character id, that character's holdings; without, every item the view carries — the buckets' contents, what characters hold, what is earmarked for the user's characters.

distribution() — the running distribution session (its method, itemOrder, participants, currentItemId, awarded so far; totals and pickerId for total value), or null.

The view is fetched once per run, and every object handed back is a copy.

Example

const [party] = (await api.treasury.buckets()).filter((b) => b.kind === 'party');
const mine = await api.treasury.holdings(character.id);
const gems = mine.filter((i) => i.category === 'gem').reduce((n, i) => n + (i.quantity ?? 1), 0);
sendMessage(`${gems} gems in the pack; the party's treasure is ${party.name}.`);

Read-only, and needs a map in a campaign

An action reads the Treasury; it does not move anything. Awarding loot is a transfer, and the transfer is the user's — from the Treasury page, the sidebar panel, or a distribution session. The campaign is the one the map the action runs on belongs to, so each call throws with a plain sentence when there is no open map, or the map is in no campaign.