Fixed json write

This commit is contained in:
2022-06-30 02:32:41 +03:00
parent 2f9e202adc
commit d9b4e1e87b
4 changed files with 12 additions and 74 deletions

27
test.py
View File

@@ -22,7 +22,7 @@ DEFAULT_PREFIX = "$" # The prefix you want everyone to have if you don't define
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix=determine_prefix, guild_subscriptions=True, intents=intents)
inter_client = InteractionClient(bot)
inter_client = InteractionClient(bot, sync_commands=True)
class DB:
@@ -169,24 +169,20 @@ class Commands:
async def write_json(guild: int, param_name: str, param: str or int):
with open('prefix.json', 'r') as _f:
try:
_jsonObject = json.load(_f)
except json.JSONDecodeError:
_jsonObject = {}
_json = json.load(_f)
except json.decoder.JSONDecodeError:
_json = {}
_f.close()
try:
_guild_conf = _jsonObject[f'{guild}']
except KeyError as error:
_guild_conf = {f'{guild}': {}}
try:
_param = _guild_conf[f"{param_name}"]
_guild = _json[f'{guild}']
except KeyError:
_param = {f'{param_name}': f'{param}'}
_json.update({f'{guild}': {}})
_guild = _json[f'{guild}']
_guild.update({f'{param_name}': f'{param}'})
_jsonObject.update(_guild_conf)
print(_jsonObject)
with open('prefix.json', 'w') as _f:
json.dump(_jsonObject, _f)
_f.close()
json.dump(_json, _f, indent=4)
_f.close()
threading.current_thread().name = "main"
@@ -310,6 +306,7 @@ async def command_set_prefix(ctx, prefix: str):
Option("prefix", "Specify prefix", OptionType.STRING, required=True),
]
)
@commands.has_permissions(administrator=True)
async def slash_set_prefix(ctx, prefix: str):
await Commands.set_prefix(ctx, prefix)