I
I
IgraMagaYT2021-08-13 13:49:54
Python
IgraMagaYT, 2021-08-13 13:49:54

I have a bonus code and when I write it I get an error, what should I do?

I'm coding on discord.py and I made myself a bonus code using json files and I'm getting an error.
The code:

@bot.command()
async def bonus(ctx):
    with open ['economy.json','read'] as f:
        money = json.load(f)

    if not str(ctx.author.id) in money:
      money[str(ctx.author.id)] = {}
      money[str(ctx.author.id)][Money] = 0

      if not str(ctx.author.id) in queue:
        emded = discord.Embed(description = '**{ctx.author.id}** Вы получили свои **5000**' )
        await ctx.send(embed = embed)
        money[str(ctx.author.id)][Money] += 5000
        queue.append(str(ctx.author.id))
        with open['economy.json',r] as f:
            json.dump(money,f)
        await asyncio.sleep(24*60)
        queue.remove(str(ctx.author.id))
      if str(ctx.author.id) in queue:
        emded = discord.Embed(description = '**{ctx.author.id}** Вы уже  получили свои **5000**' )
        await ctx.send(embed = embed)

And I added a queue, but I get an error when writing cmd:

File "C:\Users\263\Desktop\BotTest\main.py", line 65, in bonus
    with open ['economy.json','read'] as f:
TypeError: 'builtin_function_or_method' object is not subscriptable

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2021-08-13
@IgraMagaYT

Replace it with this The code is not formatted, so I didn't look further. Read about the context manager. with open['economy.json',r] as f:

U
UberPool, 2021-08-14
@UberPool

You are not using correctly with open.
Replace square brackets with round ones.
Read more about with open() .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question