There's a much faster way to do it, with /filter. Of course, you must be on that channel to get the full nicklist.
Code:
on *:dialog:<dialognamehere>:sclick:4:{
if $did(3) ischan { filter -loc $ifmatch $dname 2 }
else return $input(You're not on channel $did(3),oh,Not on channel)
}