with open("attacks.json") as json_data:
items = json.load(json_data)
if int(data["balance"]) => 0:
total = int(data["balance"]) - int(quantity) * int(items[weapon]["purchase_cost"])
total = int(total)
profileData[ctx.message.author.id]["balance"] = "{}".format(total)
with open("{}.json".format(ctx.message.author.id), "w") as json_file:
json.dump(data, json_file)
так что в основном я хочу, чтобы это работало.
profile_template = {
ctx.message.author.id: {
"name": ctx.message.author.name,
"id": ctx.message.author.id,
"balance": "1000",
"shield_hitpoints": "2500",
"defense_power": "50",
"attack_upgrade": "100%",
"healthpoints_upgrade": "100%",
"soldier#": "0",
"sniper#": "0",
"demolitionist#": "0",
"armored_vehicle#": "0",
"tank#": "0",
"spy#": "0"
}
}
Но когда я изменяю файл json, ctx.message.author.id удаляется. Как мне сохранить его при изменении файла?






Итак, когда вы открываете файл attacks.json, вы сохраняете его в переменной items.
Затем вы измените переменную profileData.
Затем вы записываете в файл переменную data.
Это источник вашей ошибки?
Также вы делаете сравнение int(data["balance"]) => 0, я думаю, вы имеете в виду int(data["balance"]) >= 0.