Skip to content

Instantly share code, notes, and snippets.

@thejoester
Last active May 24, 2025 11:54
Show Gist options
  • Save thejoester/3a266f0866adc2e3ca1b078dadbef4e7 to your computer and use it in GitHub Desktop.
Save thejoester/3a266f0866adc2e3ca1b078dadbef4e7 to your computer and use it in GitHub Desktop.
FoundryVTT Whisper Macro (v12+)
/* *********************************************************************
FoundryVTT Whispter Macro (v12+)
Author: TheJoester
Description: Macro will open a dialog with a drop-down list of
logged in users, select a user, type a message, press send and
it will send a whisper to that player.
*/ **********************************************************************
(async () => {
// Get all active users except the current user
const players = game.users.filter(u => u.active && u.id !== game.user.id);
const optionsHtml = players.map(p => `<option value="${p.id}">${p.name}</option>`).join("");
const dialog = new foundry.applications.api.DialogV2({
window: { title: "Send Private Whisper" },
content: `
<div class="form-group">
<label for="recipient">Select Recipient:</label>
<select id="recipient" name="recipient" class="w-full">
${optionsHtml}
</select>
</div>
<div class="form-group">
<label for="whisper-message">Message:</label>
<textarea id="whisper-message" name="message" rows="4" class="w-full"></textarea>
</div>
`,
buttons: [{
action: "send",
label: "Send Whisper",
default: true,
callback: (event, button, dialog) => {
const form = button.form;
const recipientId = form.querySelector("#recipient")?.value;
const message = form.querySelector("#whisper-message")?.value.trim();
if (recipientId && message) {
ChatMessage.create({
content: message,
type: CONST.CHAT_MESSAGE_TYPES.WHISPER,
whisper: [recipientId]
});
}
return true;
}
}, {
action: "cancel",
label: "Cancel"
}]
});
dialog.render({ force: true });
})()
@thejoester
Copy link
Author

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment