In your posted code, you're still using $nick in the notice.
In the code I posted, that notice is in an alias.
some identifiers, like $nick and $chan return $null when used in an alias, so you have to pass the information as a parameter.

That's what the $1 in the alias (as I posted it) represents.

Please ensure that you're using the entire code I posted, or post your code so that I can see exactly what needs to be changed and where.