-
-
Notifications
You must be signed in to change notification settings - Fork 0
Resource.Message() — Chat Card API
Resource.Message() is a public JavaScript API exposed by the Daggerheart: Resource Macros module. It allows any macro (world or compendium) to send a styled Daggerheart chat card to all connected clients and optionally broadcast a sound.
The function is available after the ready hook fires. It is safe to call from any macro executed during a live game session.
Resource.Message(options)Resource.Message() accepts a single options object.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
header |
string |
Yes | — | Title text displayed in the card header. Rendered in gold uppercase. |
text |
string |
No | undefined |
Body message text. When provided, a content area is rendered below the header. |
image |
string |
No | undefined |
Path to a background image for the body area. Only used when text is also provided.
|
sound |
string |
No | undefined |
Path to an audio file to broadcast to all connected clients. |
volume |
number |
No | 0.8 |
Playback volume for the sound, from 0.1 to 1.0. |
The function has two distinct rendering modes determined by whether text is provided.
When text is not provided, the card renders a single dark header bar with the gold title. This is the minimal form — useful for brief event announcements.
Resource.Message({ header: "-1 Fear" });When text is provided, a content area is rendered below the header. The body displays the message text in large white bold font over a dark background. If image is also provided, it is used as a full-cover background image behind a dark overlay that ensures text legibility.
Resource.Message({
header: "-1 Fear",
text: "The impending dread transforms into sudden violence."
});Resource.Message({
header: "-1 Fear",
text: "The impending dread transforms into sudden violence.",
image: "modules/daggerheart-fear-macros/assets/images/skull.webp"
});Note:
imageis silently ignored whentextis not provided. The parameter has no effect in header-only mode.
The sound parameter is independent of the rendering mode. It works in both header-only and header + body cards.
Resource.Message({
header: "+1 Hope",
sound: "sounds/lock.wav",
volume: 0.6
});The sound is broadcast to all connected clients simultaneously via Foundry's audio system.
Note: Passing
volume: 0falls back to the default0.8. There is no silent-broadcast mode — omitsoundentirely to play no audio.
Resource.Message({
header: "Fear Max!",
text: "The darkness closes in. All hope seems lost.",
image: "modules/daggerheart-fear-macros/assets/images/skull.webp",
sound: "modules/daggerheart-fear-macros/assets/sounds/fear-max.wav",
volume: 0.9
});- If
headeris missing or empty, the function logs a warning to the browser console and does not send any chat message. - If
soundpoints to a file that does not exist, Foundry's audio system will fail silently on the client side. - If
imagepoints to a missing file, the body renders with a plain dark background instead.
This API is designed to be called from within the macros you assign to Fear and Hope trigger slots. Create a world macro of type Script, then call Resource.Message() at any point in the macro body.
// Example: macro assigned to "Increase Fear" slot
Resource.Message({
header: "+1 Fear",
text: "The GM gains a Fear token. Dread fills the room.",
sound: "modules/daggerheart-fear-macros/assets/sounds/fear-rise.wav"
});- The chat card speaker name (shown above the card in the chat log) matches the
headervalue. - The visual style uses inline CSS to remain consistent across all Foundry themes and system overrides.
- The function returns a
Promise. You canawaitit inside anasyncmacro if you need to sequence actions after the message is sent.
await Resource.Message({ header: "-1 Hope" });
// code here runs after the chat message is confirmed created