I (unfortunately) don't have a background in coding, so I use coding blocks. I've tried using a levelling system code I got from someone, but it only worked once. But it keeps showing an error now.
Code
@bot.event
async def on_member_join(member):
with open('users.json', 'r') as f:
users = json.load(f)
await update_data(users, member)
with open('users.json', 'w') as f:
json.dump(users, f)
@bot.event
async def on_message(message):
await bot.process_commands(message)
if message.author.bot == False:
with open(users.json', 'r') as f:
users = json.load(f)
await update_data(users, message.author)
await add_experience(users, message.author, 5)
await level_up(users, message.author, message)
with open(users.json', 'w') as f:
json.dump(users, f)
async def update_data(users, user):
if not f'{user.id}' in users:
users[f'{user.id}'] = {}
users[f'{user.id}']['experience'] = 0
users[f'{user.id}']['level'] = 1
async def add_experience(users, user, exp):
users[f'{user.id}']['experience'] += exp
async def level_up(users, user, message):
experience = users[f'{user.id}']['experience']
lvl_start = users[f'{user.id}']['level']
lvl_end = int(experience ** (1/4))
if lvl_start < lvl_end:
await message.channel.send(f'{user.mention} has leveled up to level {lvl_end}')
users[f'{user.id}']['level'] = lvl_end
Error
Ignoring exception in on_message
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.7/site-packages/discord/client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "<string>", line 40, in on_message
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.7/json/__init__.py", line 296, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.7/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...
Not sure why it all of a sudden stopped. I (might) also need help with a code with a 'economy system' with privileges as the bot's creator. I'm still a beginner.