You need to use the character id, not their name, with 'character!'. that means you need a function to grab the character id from the name. This is not tolerant of typos. Also your split limit of 3 there seems a bit risky. If you have more than 3 elements, the ones after the 3rd will be discarded. I'd recommend using a different separator, like -- or |, so you would type say !as|Bilbo|<your outputted message> You could use anything as the symbol as long as its not going to be repeated in your message text. Here's a quick-and-dirty version of the script. on("ready", function() { const separator = '|', scriptName = 'EMAS'; const getCharacter = (name) => { const characters = findObjs({ type: 'character', name: name }); if (!characters || !characters.length) return `No Matching Characters for Name: ${name}`; else if(characters.length > 1) return "More Than One Matching Character"; return 'character|' + characters[0].id;//'character|' + characters[0].id; };
on("chat:message", function(msg) { if(msg.type == "api" && msg.content.indexOf(`!as${separator}`) === 0) { const n = msg.content.split(separator); //Splits the message into three components separated by double quotes: cmd "as" mes const as = getCharacter(n[1].trim()); // added a trim just to handle any accidental spaces const mes = n[2]; if(as.indexOf('|') !== -1) // tests to see 'as' is in format 'character!' sendChat(as, mes); else sendChat(scriptName, `/w ${msg.who} Error: ${as}. <br>Message:<br> ${mes}`); // in case of an error, sends you the message so you can copy & paste without having to retype it } }); });