Answer the question
In order to leave comments, you need to log in
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)
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
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:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question