So, im making logs for my discord bot and when i restart the program the logs are erasing itself (the logs are in a txt file) Here's the code:
import discord
from discord.ext import commands
from datetime import datetime
from datetime import date
import json
bot = commands.Bot('g4:', intents=discord.Intents.all())
bot.remove_command('help')
privat = open('C:\\Users\\pooki\\OneDrive\\Bureau\\Codes\\GBot 4\\private.json', "r")
jsondata = privat.read()
private = json.loads(jsondata)
@bot.command()
async def ping(a):
await a.send('Pong!')
logs = open('C:\\Users\\pooki\\OneDrive\\Bureau\\Codes\\GBot 4\\logs.txt', "w")
logs.write(f'{date.today().strftime("%d/%m/%Y")} at {datetime.now().strftime("%H:%M:%S")}:@{a.message.author.name} said ping.\n') #type: ignore
logs.close()
bot.run(token=str(private['token']))
When i looked on the internet it said to put the close function on my file after it writed in it but it still didn't work.