If you use the private notice event, the $chan becomes $null. There's no # in a private event. You may need to loop through the $comchan($nick,0), or just follow 5618's advice to specify the actual channel name.