首页 > 解决方案 > 如何使用python从JSON中删除特定成员

问题描述

我尝试了不同的方法,但没有任何效果。当他离开服务器时,我想从 JSON 中删除特定成员。意图开启,其余代码运行良好。有小费吗?

@client.event
async def on_member_remove(member):
    with open("users.json", "r") as f:
        users = json.load(f)

    del users[member.id]

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

例如,我想从 JSON 中删除“801014207230640168”

{"801014207230640168": {"xp": 11, "level": 1, "last_message": 1614718416.40123, "name": "BlackF00xTest"}}

标签: pythonjsondiscord.py

解决方案


推荐阅读