Last active
May 24, 2025 11:54
-
-
Save thejoester/3a266f0866adc2e3ca1b078dadbef4e7 to your computer and use it in GitHub Desktop.
FoundryVTT Whisper Macro (v12+)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ********************************************************************* | |
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 }); | |
})() |
Author
thejoester
commented
May 24, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment