A possible implementation would be to run a while loop triggered by a !clean command or observe if the current number of messages exceed a user-defined maximum. Afterwards the cleaning operation would clear everything in the channel that was for example not issued by PyBot or Pinned in Discord.