I am coding a discord.py bot and i have a command called slots. I am using a function to update the balence of the user that runs the command. The code is.
async def update_bank(user,change = 0,mode = "wallet"):
users = await get_bank_data()
users[str(user.id)][mode] = change
with open("mainbank.json","w") as f:
json.dump(users,f)
bal = [users[str(user.id)["wallet"], users[str(user.id)]["bank"]]]
return bal
But the error as said in the title is in this line.
bal = [users[str(user.id)["wallet"], users[str(user.id)]["bank"]]]
Here is the stack trace
Traceback (most recent call last):
File "/home/container/.local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "/home/container/cogs/slots.py", line 54, in slots
bal = await update_bank(ctx.author.id)
File "/home/container/cogs/slots.py", line 38, in update_bank
bal = [users[str(user)["wallet"], users[str(user)]["bank"]]]
TypeError: string indices must be integers
If anyone can help that will be great
CodePudding user response:
Pretty sure that you are simply missing the square bracket right here
bal = [users[str(user.id) ->]<- ["wallet"], users[str(user.id)]["bank"]]]