diff --git a/test.py b/test.py index 4a7564a..3c4a436 100644 --- a/test.py +++ b/test.py @@ -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) diff --git a/test2.py b/test2.py deleted file mode 100644 index 78b3a0b..0000000 --- a/test2.py +++ /dev/null @@ -1,17 +0,0 @@ -import json - - -def write_json(guild: int, param_name: str, param: str or int): - with open('prefix.json', 'r', 'utf-8') as _f: - try: - _json = json.load(_f) - except json.decoder.JSONDecodeError: - _json = {} - _json.update({f'{guild}': {}}) - print(_json) - _guild = _json[f'{guild}'] - print(_guild) - _guild.update({f'{param_name}': f'{param}'}) - print(_json) - -write_json(929446191270330452, 'test1', '34') diff --git a/test3.py b/test3.py deleted file mode 100644 index b70dde9..0000000 --- a/test3.py +++ /dev/null @@ -1,23 +0,0 @@ -my_dict = {'key': 'value'} -print(my_dict) - -my_dict.update({'another_key': 'another_value'}) # Дополняем. -print(my_dict) -my_dict.update({'another_key': 'yet_another_value'}) # Обновляем. -print(my_dict) -my_dict.update({"subdict": {}}) -subdict = my_dict['subdict'] -print(my_dict) -print(subdict) -subdict.update({'subdictkey': 'subdictvalue'}) -print(subdict) - -print(my_dict) -subdict.update({'subdictkey2': 'subdictvalue2'}) -print(my_dict) -subdict.update({'subdictkey': '33'}) - -print(my_dict) -my_dict.update({'testKey': 'testValue'}) -print(my_dict) -print(my_dict) \ No newline at end of file diff --git a/test4.py b/test4.py deleted file mode 100644 index 3c1c19b..0000000 --- a/test4.py +++ /dev/null @@ -1,19 +0,0 @@ -from os import walk - -f = [] -print(f'{f}\n----------------') -for filenames in walk('audio'): - f.extend(filenames) - break -print(f'{f}\n----------------') - - -f = f[2] - -print(f) -print(type(f)) - -i = 100 -print(i) -i = i * 4 -print(i)