Nimue's solution will work if you never issue your own
/NAMES commands (which is not a command many people really use much anymore since +i is used as much as it is). If you do use that command, then just set a timed variable with the channel name in it in an
on me:*:JOIN:#: event and unset it in the
raw 366:*: event.