删除json Discord.py中的特定数据

时间:2020-02-04 19:56:20

标签: json discord.py

@bot.command(pass_context=True)
async def example(ctx, key):
    with open('amounts.json') as f:
     amounts = json.load(f)
    if key in amounts:

       if amounts[key] > int(99):
        await ctx.send("Success")
        (DELETE IT HERE)

        _save()
        member = ctx.message.author
        this_guild = member.guild

        role = get(member.guild.roles, name='Test')
        await member.add_roles(role)
        Message = ctx.message
        await Message.delete()

       else:
         await ctx.send("Invalid!")

    else:
        await ctx.send("Invalid!")

所以我正在制作东西,我需要删除json示例中的特定东西:

{"172046029078659072": 78, "201941438": 78, "444591956": 78, "221448711": 100, "937709987": 100}

所以说我想从该文件中删除““ 201941438”:78“,我该如何在discord.py中做到这一点?

1 个答案:

答案 0 :(得分:0)

使用services.AddControllers(config => { config.Filters.Add<CustomActionFilter>(); }); 删除密钥,其中del amounts["201941438"]是您的密钥。然后将json文件保存("201941438"到磁盘。