if all you want is to have the common channels show at the end of a whois and not show if there are no common channels then try this
Code:
raw 318:*: {
  var %a = 1, %b = $comchan($2,0)
  if (!%b) { return } 
  while %a <= %b {
    var %chan = $addtok(%chan,$comchan($2,%a),44)
    inc %a
  }
  echo -a $2 has the following channels common with you: %chan
}