Your code will be easier to read if you wrap it inside the "code" keyword instead of using "quote". On a side note, the line where you set the local var %k to a string of 2 apostrophes is not needed, as you are immediately redefining it. If you really did need to make it be blank, you would just use 2 double-quotes instead - or better yet just put nothing behind %kk or else use $null.

The part that needs to change is your while-loop where you slowly build your %text string and the immediate next line is displaying the entire contents of that string. Instead, it will need to check the length each time before it adds the next string. If it's too long, it displays the prior contents of %text then makes that variable blank. Then it does like before, adding the new contents to the %text which is going to safely be below the limit. I didn't test this, but it should work:

old:

Code:
while (%x) {
%kk = $ini(%command_file,%k,%x)
var %text %text ! $+ %kk => $readini(%command_file,n,%k,%kk) $(|)
dec %x
} 
.msg # .w $nick = %text


new:

Code:
      while (%x) {
        %kk = $ini(%command_file,%k,%x)
        var %temp $readini(%command_file,n,%k,%kk)
        if ( $len(%text ! $+ %kk => %temp $(|) ) ) > 99 {
          .msg # .w $nick = %text | var %text
        }
        var %text %text ! $+ %kk => %temp $(|)
        dec %x
      }
      .msg # .w $nick = %text



Additional work may be needed regarding the max message length. Above I arbitrarily used 99, and you can change it to whatever the unstated length will be. I don't use twitch, but I suspect the true limit is not just the visible part of the message, but includes other strings such as the server name or the nick sending or receiving the whisper or the #channelname. You might need to calculate the allowed length each time, based on the current values each time someone uses !cmd.