Slight alteration to your code using groups and an alias.

Code:
on 1:Text:!DNS *:#Channel: { .enable #DNS | dns $2 | set %x $2 }

#DNS off
on *:dns: {
  $iif($raddress,chk resolved,chk notresolved) 
}
#DNS end

alias -l chk {
  if ($1 == resolved) { msg #channel Resolved $dns(1) to $raddress | .disable #DNS }
  if ($1 == notresolved) { msg #channel Couldn't resolve %x | .disable #DNS }
  unset %x
}