【问题标题】:Command raised an exception: KeyError: '560849136899850261'命令引发异常:KeyError:'560849136899850261'
【发布时间】:2021-10-07 17:00:30
【问题描述】:

我有一个问题,我无法将 ["cash"] 放入我的 json 中,谢谢你帮助我

我的代码:

    a = users[str(guildb.id)] = {}
    b = users[str(guildb.id)][str(user.id)]["cash"] = 5000
    c = users[str(guildb.id)][str(user.id)]["bank"] = 10000

Error

【问题讨论】:

  • 请复制和粘贴回溯文本而不是图像 - 请参阅 How to Ask

标签: python json python-3.x discord


【解决方案1】:

users 是字典。 users[str(guildb.id)] 是字典。但在你的情况下users[str(guildb.id)][str(user.id)] 不是字典。

你需要这样做:

a = users[str(guildb.id)] = {}
b = users[str(guildb.id)][str(user.id)] = {}
c = users[str(guildb.id)][str(user.id)]["cash"] = 5000
d = users[str(guildb.id)][str(user.id)]["bank"] = 10000

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 2021-04-08
    • 2018-12-09
    • 2019-09-19
    • 2019-12-08
    • 1970-01-01
    • 2011-01-14
    相关资源
    最近更新 更多