python - 从 JSON Discord PY 中删除所有用户信息

标签 python python-3.x discord discord.py

当在聊天中输入 !reset 时,我正在尝试重置 discord 服务器的“奖品”JSON 信息中的每个人。我知道如何在个人基础上做到这一点,但不是每个人。

def reset_prize(user: discord.User, prize: int):
    id = user.id
    if id not in stats:
        stats[id] = {}
    stats[id]["prize"] = 0
    print("{} prizes were reset to 0".format(user.name))
    save_stats()

@client.event
async def on_message(message, user=discord.User):
    if message.content.startswith("!reset"):
            x = message.server.members
            for member in x:
                reset_prize(member, 0)

最佳答案

你可以使用字典的.clear()属性

me={
    "name1":12,
    "name2":123,
    "ages":{
        "1":12,
        "1":111
    }
}


me['ages'].clear() #clear all the items inside the obj `ages
me.clear() #clear everything inside the `me` dict
print(me)
>>> {}

关于python - 从 JSON Discord PY 中删除所有用户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54319648/

相关文章:

python - 根据pandas中的条件聚合(连接)文本列

javascript - “JSON 输入意外结束”

python - 分解长路径名

python - 如何禁用嵌入中字符串的 Markdown ?

java - 如何使用 JDA 将带有消息的文件发送到 Discord?

python - 无法从 python 代码访问 Heroku 配置变量

python - 使用 Google Colab 删除 Google Drive 上的文件

python - 我在尝试调用方法时收到名称错误

python - 从 PyParsing 中的字符串中检索多个重叠匹配项

python-3.x - python 'while'代码的语法错误