There is alreay an auto join command.
To add a channel to your auto command try:
/msg NickServ AJOIN ADD #channel
To add a channel that uses a key try:
/msg NickServ AJOIN ADD #channel key
To add all the channels you currently are try:
/msg NickServ AJOIN ADDALL
To see the complete list on your autojoin try:
To remove a channel try:
/msg NickServ AJOIN DEL #channel
To delete all your channels on autojoin try:
/msg NickServ AJOIN CLEAR