Files
discord_bot/test2.py
2022-06-29 08:04:24 +03:00

39 lines
945 B
Python

import json
def write_json(guild: int, param_name: str, param: str or int):
with open('prefix.json', 'r+', encoding='utf-8') as _f:
try:
_jsonObject = json.load(_f)
except json.decoder.JSONDecodeError:
_jsonObject = {}
try:
_guild_conf = _jsonObject[f"{guild}"]
except KeyError:
_guild_conf = {f"{guild}": {}}
print(_jsonObject)
print(_jsonObject)
try:
_param = {f"{param_name}": f"{param}"}
except KeyError:
_param = {f"{param_name}": f"{param}"}
print(_param)
_guild_conf.update(_param)
print(_jsonObject)
_jsonObject.update(_guild_conf)
_guild_conf = _jsonObject[f"{guild}"]
print(_jsonObject)
print(_guild_conf)
print(_param)
with open("prefix.json", "w") as _f:
json.dump(_jsonObject, _f)
_f.close()
write_json(929446191270330452, 'rr', '34')