Code:
if (%joinmsg) msg $chan 7  [ [ %joinmsg ] ] 

This code should work, basically we're just checking to see if %joinmsg has a value before we send the msg to the chan.