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 .
×

Changing a sendChat to a Whisper

1786161220

Edited 1786171824
I'm embarrassed that I don't know this, but I am trying to go back into my various scripts and whisper things in order to cut down on chat window traffic for players. So I am trying to make the many sendChat commands I have into whispers. Well, I'm messing up. I do know how to send a whisper from the chat window input box: but I've put off using it in mods/API until now and am a bit stuck. <a href="https://help.roll20.net/hc/en-us/articles/360037256754-API-Chat#API:Chat-chat:message" rel="nofollow">https://help.roll20.net/hc/en-us/articles/360037256754-API-Chat#API:Chat-chat:message</a> &nbsp;is too difficult for me to understand. I don't understand anything in the Callback parameters table at the start despite it mentioning whisper a number of times. So far, sendChat("some name or short message", full message or helper); has been perfect for me. But this link doesn't help me with how to set up a whisper. At one point, a "quick answer" in searching for "mod whisper sendChat" said to use /w name but I can't get that to work.&nbsp; Hopefully it's really simple. Here's my first sendChat I'm trying to whisper. charName is the name of a character, in this case, Rolleo.&nbsp;Panel is a helper expression from ROTTO to construct a formatted chat output, panel(colour expression, title, text and buttons): sendChat(charName, panel(userhex, TopCaption, illus + TopBtns + BottomBtns + LinksSection)); I've tried: sendChat(charName, "/w " + charName + panel(userhex, TopCaption, illus + TopBtns + BottomBtns + LinksSection)); But this gives me the following error in the Mod Output Console: {"who":"error","type":"error","content":"Unable to find a player or character with name: Rolleo&lt;div"} I must be missing something ridiculously simple? And should I have the whisper go to the character name or msg.who? The latter wouldl allow folks to select one of the party members and look at their characteristics and other things. In that case, I'd still like the whisper to also go to me as the GM so that what is done is recorded by the chat archive?
1786199989
StéphaneD
Pro
Sheet Author
API Scripter
Hi Looks like charName does not contain what you think it should.&nbsp; Have you checked it is loaded with ‘Rolleo’ and not ‘Rolleo&lt;div’ ?
1786201313
The Aaron
Roll20 Production Team
API Scripter
You are so very close! &nbsp;The issue is the character name is getting smashed against the panel output with no separating space. Minimal change is: sendChat(charName, "/w " + charName + " " + panel(userhex, TopCaption, illus + TopBtns + BottomBtns + LinksSection)); However, I would suggest: sendChat(charName, `/w "${charName}" ` + panel(userhex, TopCaption, illus + TopBtns + BottomBtns + LinksSection)); The back tick ` quotes let you expand expressions inside ${ } and thus let you also have quotes around the character name. &nbsp;Without quotes, it looks for the first space to find the whisper target name, so if you have "The Aaron" and "The Tim" in the game, "/w the Aaron sup!" might go to either "The" &nbsp;
1786211966

Edited 1786212037
StéphaneD said: Hi Looks like charName does not contain what you think it should.&nbsp; Have you checked it is loaded with ‘Rolleo’ and not ‘Rolleo&lt;div’ ? Salut et merci, Stéphane. Yeah, that ‘Rolleo&lt;div’ is extremely weird, isn't it? charName does have the correct info as "Rolleo" showing on top of the chat box. It turns out I do have a hanging &lt;div...&gt; just before the sendChat. I wonder if that caused it? LinksSection = "&lt;div style='font-size:16px;margin-bottom:4px;'&gt;" + "&lt;b&gt;Links&lt;/b&gt; " + "&lt;span style='font-style:italic;color:#992B00;font-size:12px;'&gt;Click: a link will appear, below.&lt;/span&gt;" + "&lt;/div&gt;" + "&lt;div style='text-align:center;'&gt;" + btnlink + "&amp;nbsp;&amp;nbsp;" + btnCamp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sendChat(charName, "/w " + charName + panel(userhex, TopCaption, illus + TopBtns + BottomBtns + LinksSection)); }); Huh, I still get the same error on the Mod Output Console when I close it, unfortunately: "&lt;div style='text-align:center;'&gt;" + btnlink + "&amp;nbsp;&amp;nbsp;" + btnCamp + "&lt;/div&gt;"; Might be another one somewhere before my code, but until I changed the sendChat to my attempt at whisper, it was all working fine. I'll see what Aaron has to say.&nbsp;
1786213239
StéphaneD
Pro
Sheet Author
API Scripter
The syntax is /w followed by a space followed by the target character name (embedded in double quotes if this name contains a space) followed by a space and then the command to whisper&nbsp; So you need to check that there is at least one space between charName and whatever output your panel() function produces&nbsp; The best solution with this kind of issue is to use string interpolation with backticks as suggested by The Aaron&nbsp;
The Aaron said: You are so very close! &nbsp;The issue is the character name is getting smashed against the panel output with no separating space. Minimal change is: sendChat(charName, "/w " + charName + " " + panel(userhex, TopCaption, illus + TopBtns + BottomBtns + LinksSection)); However, I would suggest: sendChat(charName, `/w "${charName}" ` + panel(userhex, TopCaption, illus + TopBtns + BottomBtns + LinksSection)); The back tick ` quotes let you expand expressions inside ${ } and thus let you also have quotes around the character name. &nbsp;Without quotes, it looks for the first space to find the whisper target name, so if you have "The Aaron" and "The Tim" in the game, "/w the Aaron sup!" might go to either "The" &nbsp; OK that works Aaron (your suggestion), thanks a lot. I did need to go into the individual characters to add Tim M to "Can be Edited and Controlled by". All Players was not good enough. I'll make sure I add the guys' names when we restart. Now off to whisper all my menus and submenus and add , null, {noarchive:true} to them so I don't clutter up the chat archive. I really only need to record the results of things the characters do with their menus (turn undead, transfer equipment to another player or unnamed place, buy stuff, weapon strikes, etc, etc)