@bot.event
async def on_message(message):
await bot.process_commands(message)
if message.author == bot.user:
return
with open('users.json', 'r') as f:
users = json.load(f)
async def update_data(users, user):
if not str(user.id) in users:
users[str(user.id)] = {}
users[str(user.id)]['experience'] = 0
users[str(user.id)]['level'] = 1
await update_data(users, message.author)
await add_experience(users, message.author, 5)
await level_up(users, message.author, message.channel)
with open('users.json','w') as f:
json.dump(users, f)
async def add_experience(users, user, exp):
users[str(user.id)]['experience'] += exp
async def level_up(users, user, channel):
experience = users[str(user.id)]['experience']
lvl_start = users[str(user.id)]['level']
lvl_end = int(experience * (1/10))
if lvl_start < lvl_end:
await channel.send(":thumbsup: {}, вы повысились до {} уровня! :thumbsup: ".format(user.mention, lvl_end))
users[user.id]["level"] = lvl_end
Ошибка такова:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\stas\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "level_system.py", line 44, in on_message
await level_up(users, message.author, message.channel)
File "level_system.py", line 59, in level_up
users[user.id]["level"] = lvl_end
KeyError: 347340011580162058