It does that because $nick($chan,0,a) returns a number, and /echo syntax is:

/echo [color number] [params/window] <text>

Use -a, as Collective suggested.