TMI is Twitch Messaging Interface.
That is the name of Chat itself.
Do you mean tmi.js instead?
Then you have asked a “how do I do x in TMI.js” and that question is better suited to the TMI.js forums/tracker/support sections. Which is not on this forum.
You need to wrap my pseudo code into the message processor function that TMI.js provides. if you are using tmi.js