/fvtt-dev:fvtt-chat-messagesfrom fvtt-dev
This skill should be used when creating chat messages, sending roll results to chat, configuring speakers, implementing whispers and roll modes, or hooking into chat message rendering.
Ships in fvtt-dev. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Domain: Foundry VTT Module/System Development Status: Production-Ready Last Updated: 2026-01-05
ChatMessage documents display in the chat log and handle rolls, whispers, and player communication. Understanding message creation and hooks is essential for game system features.
{
_id: "documentId",
author: "userId", // Who created the message
content: "<p>HTML</p>", // Message content
flavor: "Roll description", // Flavor text for rolls
speaker: { // Who is "speaking"
scene: "sceneId",
actor: "actorId",
token: "tokenId",
alias: "Display Name"
},
whisper: ["userId"], // Private recipients
blind: false, // GM-only visibility
rolls: [], // Dice roll data
sound: "audio/path.ogg", // Sound to play
flags: {} // Custom data
}
await ChatMessage.create({
content: "Hello, world!"
});
await ChatMessage.create({
content: "I attack the dragon!",
speaker: ChatMessage.getSpeaker({ actor: myActor })
});
await ChatMessage.create({
content: `
<h2>Critical Hit!</h2>
<p>You deal <strong>24</strong> damage.</p>
`,
speaker: ChatMessage.getSpeaker({ token: myToken })
});
await ChatMessage.create({
content: "Attack roll",
flags: {
"my-module": {
rollType: "attack",
targetId: target.id
}
}
});
const roll = new Roll("1d20 + @mod", { mod: 5 });
await roll.evaluate();
await roll.toMessage({
speaker: ChatMessage.getSpeaker({ actor }),
flavor: "Attack Roll"
});
await roll.toMessage({
speaker: ChatMessage.getSpeaker({ actor }),
flavor: "Stealth Check"
}, {
rollMode: game.settings.get("core", "rollMode")
});
const attackRoll = new Roll("1d20 + 5");
const damageRoll = new Roll("2d6 + 3");
await attackRoll.evaluate();
await damageRoll.evaluate();
await ChatMessage.create({
speaker: ChatMessage.getSpeaker({ actor }),
flavor: "Attack and Damage",
rolls: [attackRoll, damageRoll]
});
// From controlled token (default)
const speaker = ChatMessage.getSpeaker();
// From specific actor
const speaker = ChatMessage.getSpeaker({ actor: myActor });
// From specific token
const speaker = ChatMessage.getSpeaker({ token: myToken });
// Custom alias
const speaker = ChatMessage.getSpeaker({ alias: "The Narrator" });
{
scene: "sceneId", // Scene where speaker is
actor: "actorId", // Actor document ID
token: "tokenId", // Token document ID
alias: "Display Name" // Fallback name
}
const actor = ChatMessage.getSpeakerActor(message.speaker);
| Mode | Visibility | Command |
|---|---|---|
| Public | Everyone | /publicroll |
| GM | Roller + GMs | /gmroll |
| Blind | GMs only | /blindroll |
| Self | Roller only | /selfroll |
// Get current setting
const rollMode = game.settings.get("core", "rollMode");
// Apply to roll
await roll.toMessage({
speaker: ChatMessage.getSpeaker({ actor })
}, {
rollMode: rollMode
});
// Single user
await ChatMessage.create({
content: "Secret message",
whisper: [targetUserId]
});
// Multiple users
await ChatMessage.create({
content: "Group secret",
whisper: [user1Id, user2Id]
});
// All GMs
await ChatMessage.create({
content: "GM only",
whisper: game.users.filter(u => u.isGM).map(u => u.id)
});
// GM sees content, others see "???"
await ChatMessage.create({
content: "Secret roll result: 15",
blind: true,
whisper: game.users.filter(u => u.isGM).map(u => u.id)
});
Hooks.on("renderChatMessageHTML", (message, html, context) => {
// message: ChatMessage document
// html: HTMLElement
// context: Rendering context
// Add custom styling
if (message.flags["my-module"]?.critical) {
html.classList.add("critical-hit");
}
// Add buttons
const button = document.createElement("button");
button.textContent = "Apply Damage";
button.addEventListener("click", () => applyDamage(message));
html.querySelector(".message-content").append(button);
});
Hooks.on("preCreateChatMessage", (message, data, options, userId) => {
// Modify before creation
message.updateSource({
content: data.content + " (modified)"
});
// Return false to cancel
return true;
});
Hooks.on("createChatMessage", (message, options, userId) => {
// After creation, for all clients
console.log("New message:", message.content);
});
Hooks.on("chatMessage", (chatLog, messageText, chatData) => {
// When user sends message via input
// Return false to prevent default handling
if (messageText.startsWith("/custom")) {
handleCustomCommand(messageText);
return false;
}
});
async function attackRoll(actor, target) {
const roll = new Roll("1d20 + @mod", actor.getRollData());
await roll.evaluate();
await roll.toMessage({
speaker: ChatMessage.getSpeaker({ actor }),
flavor: `Attack vs ${target.name}`,
flags: {
"my-system": {
type: "attack",
targetId: target.id,
total: roll.total
}
}
});
}
// Handle button clicks
Hooks.on("renderChatMessageHTML", (message, html) => {
const flags = message.flags["my-system"];
if (flags?.type !== "attack") return;
html.querySelector(".apply-damage")?.addEventListener("click", () => {
const target = game.actors.get(flags.targetId);
// Apply damage logic
});
});
await ChatMessage.create({
content: `
<div class="roll-result">
<h3>Attack Roll: 18</h3>
<details>
<summary>Details</summary>
<p>Base: 1d20 = 13</p>
<p>Modifier: +5</p>
</details>
</div>
`
});
await ChatMessage.create({
content: "The bell tolls...",
sound: "sounds/bell.ogg"
});
// WRONG - total is undefined
const roll = new Roll("1d20");
await roll.toMessage(); // roll.total undefined!
// CORRECT
const roll = new Roll("1d20");
await roll.evaluate();
await roll.toMessage();
// WRONG - uses first controlled token
ChatMessage.getSpeaker();
// CORRECT - specify the token
ChatMessage.getSpeaker({ token: specificToken });
// Roll messages override whisper with rollMode
// Use rollMode for roll messages:
await roll.toMessage({}, {
rollMode: "gmroll" // Not whisper: [...]
});
// WRONG - always public
await roll.toMessage();
// CORRECT - respect user setting
await roll.toMessage({}, {
rollMode: game.settings.get("core", "rollMode")
});
// Updating too fast causes UI issues
// Wait for notification to fade (~3 seconds)
const msg = await ChatMessage.create({ content: "Loading..." });
setTimeout(() => {
msg.update({ content: "Done!" });
}, 3500);
// Check if message is visible to current user
if (!message.visible) return;
// Check if content is visible (not just presence)
if (message.isContentVisible) {
// Safe to read content
}
ChatMessage.getSpeaker() for proper speakerawait roll.evaluate() before toMessagegame.settings.get("core", "rollMode")renderChatMessageHTML hook for customizationLast Updated: 2026-01-05 Status: Production-Ready Maintainer: ImproperSubset
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
17 skills in this plugin
/fvtt-active-effectsThis skill should be used when creating or applying Active Effects, working with effect changes and modes (ADD, MULTIPLY, OVERRIDE, CUSTOM), implementing duration tracking for combat, or handling effect transfer from items to actors./fvtt-applicationsThis skill should be used when creating custom windows with ApplicationV2, building forms with FormApplication, using Dialog for prompts, understanding the render lifecycle, or migrating from Application v1 to ApplicationV2./fvtt-canvasThis skill should be used when working with the Foundry canvas, PIXI.js rendering, canvas layers, placeable objects (tokens, tiles, drawings), render flags for performance, or canvas lifecycle hooks like canvasReady.npx claudepluginhub impropersubset/hh-agentics --plugin fvtt-dev