Discord.py:json.decoder.JSONDecodeError:预期值:第1行第1列(字符0)

时间:2019-03-18 23:31:24

标签: python discord.py

我绝对不知道这个错误意味着什么。我无休止地用Google搜索,仅花了5天的时间就解决了这一错误。请帮我。这是针对一个不和谐的机器人,它在python中保留了xp系统,并将播放器的信息存储在.json文件中。

Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\Michael\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 307, in _run_event yield from getattr(self, event)(*args, **kwargs) File "JahBot.py", line 208, in on_message users = json.load(f) File "C:\Users\Michael\AppData\Local\Programs\Python\Python36\lib\json\__init__.py", line 299, in load parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File "C:\Users\Michael\AppData\Local\Programs\Python\Python36\lib\json\__init__.py", line 354, in loads return _default_decoder.decode(s) File "C:\Users\Michael\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Users\Michael\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

我将我的货币代码放在这里:

`@client.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:
        users = json.dump(users, f)

@client.event
async def on_message(message):
    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.channel)

    with open('users.json', 'w') as f:
        users = json.dump(users, f)

async def update_data(users, user):
    if not user.id in users:
        users[user.id] = {}
        users[user.id]['experience'] = 0
        user[user.id]['level'] = 1

async def add_experience(users, user, exp):
    users[user.id]['experience'] += exp

async def level_up(users, user, channel):
    experience = users[user.id]['experience']
    lvl_start = users[user.id]['level']
    lvl_end = int(experience ** (1/4))

    if lvl_start < lvl_end:
        await client.send_message(channel, '{} has leveled up to level {}'.format(user.mention, lvl_end))
        users[user.id]['level'] = lvl_end`

0 个答案:

没有答案