Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

sendChat with Experimental Sandbox and dice rolls

1763413719

Edited 1763414550
I decided to look at Group Initiative to see why it wasn't working for 2024 sheets. As I was diving in I noticed that anytime you call `sendChat` with a message that contains either `/roll ...` or an inline roll `[[1d20]]` it seems to fail silently. The roll never gets sent to chat, and it never gets the a callback that you pass in. Switching to the Default sandbox does not have this issue, rolls are processed fine and sent to chat. While there might be some other issues with the Group Initiative script, the issue with `sendChat` seems to be a blocker on it working since it requires the Experimental Sandbox to get access to the 2024 sheet's attributes. Here's the quick script I used for testing. In Experimental only the first message gets logged after sending. The 2nd chat that contains a roll command doesn't get logged. (note: not passing in a callback function the chat message shows up on the first and not the second) on("chat:message", async function(msg) { if(msg.content == 'Test') { // Does send to chat await sendChat('Testing', 'Some Message', (opts) => { log(`Opts: ${JSON.stringify(opts)}`); }); // Does not send to chat await sendChat('Testing', '/roll 1d20', (opts) => { log(`Opts: ${JSON.stringify(opts)}`); }); } }); And the output in the sandbox console, only the plain text chat message is logged Restarting sandbox by user request... detected currently running sandbox... restarting "%cRoll20 Kingmaker Module log| kScaffold Loaded" "##########> Sandbox [EXPERIMENTAL 2025-10-22] : Ready fired after 9.78s, 914 objects." "Opts: [{\"who\":\"Testing\",\"type\":\"general\",\"content\":\"Some Message\",\"playerid\":\"API\",\"avatar\":false,\"inlinerolls\":[]}]" Anyways not sure if maybe this helps narrow down where the actual issue Roll20 needs to fix or not, but though I'd post what I noticed since I didn't see anyone talking about the issue with `sendChat` itself.
1763416674
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Doesn't affect this test, but just want to note that awaiting send chat doesn't really do anything as it doesn't return anything other than undefined.
1763417883
The Aaron
Roll20 Production Team
API Scripter
As Scott mentioned, sendChat is no asynchronous.  You can use this function if you want something to await: const sendChatP = (msg) => new Promise((resolve) =>{ sendChat('',msg.replace(/\[\[\s+/g,'[['),(res)=>{ resolve(res[0]); }); });
1763419156
The Aaron
Roll20 Production Team
API Scripter
I confirmed that sendChat() is not making the callback in Experimental.  I've reported it to the devs to get addressed.
Yeah I was testing some things with the async... I think it stemmed from the docs mentioning using sendChat with the callback is async, but i think specifically it probably meant that internally the sendChat function calls the callback async, rather than sendChat itself being async.