【问题标题】:How to fix 'json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)' error?如何修复 'json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)' 错误?
【发布时间】:2020-12-04 22:40:52
【问题描述】:

每次有人写错误都会出现。我希望我没有犯通常的错误

代码:

@client.event
async def on_message(message):
    await client.process_commands( message )

    with open('C:\\Ультилиты\\ProgramBotDiscord\\lvl.json', 'r' ) as f:
        users = json.load(f)
        
    async def update_data(users, user):
        if not user in users:
            users[user] = {}
            users[user]['exp'] = 0
            users[user]['lvl'] = 1
    await update_data(users, message.author.id)

    with open('C:\\Ультилиты\\ProgramBotDiscord\\lvl.json', 'w' ) as f:
        json.dump(users, f)

命令:

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Programs\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "501.py", line 319, in on_message
    users = json.load(f)
  File "C:\Programs\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Programs\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Programs\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Programs\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)

【问题讨论】:

  • 您的 JSON 文件包含什么...?
  • 没什么@deceze images
  • @MOnsterHak 那么您认为 JSON 可以加载什么? ;)

标签: python discord discord.py


【解决方案1】:

这会是您的问题,要使其正常工作,您需要 json 文件中的数据。如果你愿意,你可以有一个系统,比如使用 try: 和 except: 来尝试接收数据,如果失败,打印出一条消息或其他东西。

【讨论】:

    猜你喜欢
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 2018-11-12
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    • 1970-01-01
    • 2020-03-30
    相关资源
    最近更新 更多