英文:
when my bot run, it clear data file by itself
问题
I don't want to bot clear data txt file.
英文:
I'am trying to Write a bot that check fivem(It Just a Game) log and if item name and item count equals to data txt file then do something.
But when on_message function start working by send a message in discord server, data file be cleared.
My Code:
@client.event
async def on_message(message):
ms_id = message.channel.id
n_log = message.content.split()
print(f"[INFO] : {message.content.split()}")
Craft_File_Read = open("Craft_Request.txt", "r")
Craft_File_Read_Data = Craft_File_Read.read()
Craft_item_File_Write = open("Craft_Request.txt", "w")
split_craft_data = Craft_File_Read_Data.split(",")
if ms_id == 1116113589456085156:
print(n_log[10])
if split_craft_data[1] == "Pistol":
benzin_value = 10 * int(split_craft_data[2])
rafin_value = 10 * int(split_craft_data[2])
essence_value = 10 * int(split_craft_data[2])
iron_piece_value = 5 * int(split_craft_data[2])
black_money_value = 60000 * int(split_craft_data[2])
if split_craft_data[0] == n_log[10]:
print("00000000000000")
print(n_log[1])
if n_log[1] == 'Gozashtan':
print("11111111111")
del n_log[0]
del n_log[len(n_log) - 2]
split_n_log = n_log[4].split("(")
split_n_log_end = split_n_log[1].replace(")", "")
if split_n_log[0] == 'petrol':
if int(split_n_log_end) == benzin_value:
check_item_pistol[0] = True
await message.reply("Sabt Shod!")
if all(check_item_pistol) == True:
Item_Check = Craft_File_Read_Data.replace(split_craft_data[3], 'True')
Craft_item_File_Write.write(Item_Check)
I Don't Want To Bot Clear data txt file
答案1
得分: 0
从我理解的情况来看,您想要追加内容到文件而不是覆盖它。在这种情况下,您应该以追加模式("a")而不是写入模式("w")打开文件。
Craft_item_File_Write = open("Craft_Request.txt", "a")
# 保持追加到文件而不是覆盖它。
英文:
From what I am understanding, you want to append to the file and not overwrite it. In that case you should open the file with appending mode ("a") and not writing mode ("w").
...
Craft_item_File_Write = open("Craft_Request.txt", "a")
# Keeps appending to the file instead of overwriting it.
...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论