You cant really do it but kinda.
You could create a variable with the scope as bot. You would then set up an after incoming message hook which would increment this variable every time. Once the variable is equal to 400 you would set a boolean variable to true and then you would check this variable at the start of your bot and if its true just end the convo. The problem with this is that people can still send a message to your bot which will use 1 message but then the bot would just end.