Depending on the chanserv and your access level for the channel you may be able to just iidentify to the channel services bot and have that bot invite you.
/cs identify #channel <pass>
/cs invite #channel

you may only need to identify with nickserv, as is the case with Dalnet
Quote:

-ChanServ- ***** ChanServ Help *****
-ChanServ- Command - INVITE
-ChanServ- Usage - INVITE <channel>
-ChanServ-
-ChanServ- Invites the sender to a channel that is set to invite only (mode
-ChanServ- +i). Used mainly for channels where the MLOCK is set +i. You
-ChanServ- cannot invite other users to a channel via ChanServ.
-ChanServ- Limited to channel AutoOps or above.
-ChanServ-
-ChanServ- Example:
-ChanServ- /msg ChanServ@services.dal.net INVITE #DragonRealm
-ChanServ- ***** End of Help *****



as far as the code shown by Orionsbelt I would strongly suggest that a user level be used with that, or anyone you know that sees the posting here will be able to use it to be invited as well.