well that code has to be in de onrecieved event... so you'll get something like this:
code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MsgKind){
if(Message.charAt(0)=="." && Message.charAt(1)=="/" && Message.charAt(2)=="x" && Message.charAt(3)==" "){
ChatWnd.SendMessage("/close");
}
}
that should work...