So you’d always be added messages to the messages array?
Thats not a good idea. as your bot will take exponentitally longer to write the messages.txt file as you will have to write the file competely every time instead of just appending to it.
For a log of messages it’s generally better to append to a flat file as raw messages from the server, like you are currently doing.
And process that flat file later.
As, to do it the way you propose
- Load the file
- Json parse the file
- Push an item to the messages array
- json encode the array again
- write the whole json blob back to a file
Your bot won’t be able to keep up.