1

I am making a python code that purges a users messages. The only problem is when it writes to file it replaces and deletes the previous code Example:

https://cdn.upload.systems/uploads/ZTjM7EON.gif

Current Code:

                    async for mss in channel.history(limit=None):
                        if logmsgs == "True":
                            f = open("LoggedMessages.txt","w",encoding="utf-8")
                            f.writelines(mss.content + "\n")
                            f.close()
  • 1
    Have a look e.g. [here](https://docs.python.org/3/library/io.html#io.FileIO) in the docs: opening a file with `w` means you want to overwrite it – lucidbrot Dec 27 '21 at 14:17
  • 1
    I hence believe your question is a duplicate of [How do you append to a file?](https://stackoverflow.com/questions/4706499/how-do-you-append-to-a-file) - is the answer there useful to you? – lucidbrot Dec 27 '21 at 14:18

0 Answers0