0
@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!")

So I was making something and I need to delete a specific thing in json example:

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

So say I want to delete " "201941438": 78 " out of that file how would I do that in discord.py?

Silent
  • 3
  • 5

1 Answers1

0

Delete the key with del amounts["201941438"] where "201941438" is your key. Then save (dump) the json file back to disk.

WayToDoor
  • 1,180
  • 9
  • 24