1. I forgot to mention that the curly-brace can touch the event's colon preceding it, but should should not be touching the characters following it.

2. I don't understand from your example what you're wanting. I thought you were saying that if someone says "!codeword @nickname" that the bot should say "$nick says hello to @nickname", where @nickname being the 2nd word would be represented by $2.

If you're wanting a random nick from a channel which is not either the bot nor the nick using !codeword, perhaps something like:

Code:
//var %randnick | while (1) { var %randnick $nick($chan,$rand(1,$nick($chan,0))) | if ($istok($me $nick,%randnick,32)) var %randnick | else break } | echo -a %randnick