The problem you are having, is due to using the wrong event.
The on INVITE event triggers when a user invites you to a channel.
What you want to do is watch for someone setting mode +i
You can use the ON MODE or ON RAWMODE for this.
See the help file for more details.