Код:
#lvl system
os.chdir(r'C:\Python1\12344\venv')
@bot.event
async def on_message(message):
with open('lvl.json', 'r') as f:
lvl = json.load(f)
await update_data(lvl, message.author)
await add_xp(lvl, message.author, 5)
await level_up(lvl, message.author, message.channel)
with open('lvl.json', 'w') as f:
json.dump(lvl, f)
async def update_data(lvl, user):
if not user.id in lvl:
lvl[user.id] = {}
lvl[user.id]['xp'] = 0
lvl[user.id]['level'] = 1
async def add_xp(lvl, user, exp):
lvl[user.id]['xp'] += 1
async def level_up(lvl, user, channel):
xp = lvl[user.id]['xp']
lvl_start = lvl[user.id]['level']
lvl_end = int(xp ** (1/4))
if lvl_start < lvl_end:
await bot.send_message(channel,'{} повысил свой уровень до {}'.format(user.mention, lvl_end))
lvl[user.id]['level'] = lvl_end
Ошибка:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Python1\12344\venv\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:/Python1/12344/venv/134567890.py", line 238, in on_message
lvl = json.load(f)
File "C:\Python38-32\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
File "C:\Python38-32\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Python38-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python38-32\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)