Hi @MMJJ882 and welcome to the Mattermost forums!
Data retention policies are a great way to do that, but they’re not available in the teams edition unfortunately.
You can do that directly in the database, if you like, so if it’s only the last 24hrs worth of messages you want to keep, you could run the following query in regular intervals on your database (this is MySQL syntax, not sure what you’re using):
update Posts set DeleteAt=unix_timestamp()*1000 where createat < (unix_timestamp()-86400)*1000 AND DeleteAt != 0;
The mattermost clients will not recognize the change here immediately, though, since this change has been carried out directly in the database and that is basically unsupported, but if you also restart the server after the cleanup, they might catch up automatically; otherwise a reload (F5, CTRL-r) in the application helps to get rid of the old posts in the currently open channel.
Another option would be to iterate over all channels in your installation and use the GetPostsForChannel API Call to delete them; this should also automatically refresh the clients.
If you only want the messages from today and the system should wipe all posts at midnight, it’s even easier, because then you can just have a cronjob running at 23:59 which sets all available posts to deleted:
update Posts set DeleteAt=unix_timestamp()*1000 WHERE DeleteAt=0;
Not sure if that would help or work for you, let me know, if you need additional help.