Discord.py – Deposit command in Economy System Bot doesn’t work properly

So i coded an Economy System bot, that should be able to subtract Money from the wallet and put it into the bank. But every time i try to execute the commands "deposit" and "withdraw" like it should be executed (When i execute it in a wrong way it sends the Messages it's supposed to send in this case). I suspect, that the Problem is the if statement "if amount>bal[0]", but i don't know. Anyways, Here's my Code and the Error it gives out, when i try to execute "deposit" and "withdraw" (I'll just post the deposit command here, because withdraw and deposit are almost equal):

async def get_bank_data():
    with open("mainbank.json", "r") as f:
            users = json.load(f)
    return users

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 user

async def deposit(ctx,amount = None):
    if amount == None:
        await ctx.send("Bitte gebe den Betrag an!")

    bal = await update_bank(ctx.author)

    amount = int(amount)
    if amount>bal[0]:
        await ctx.send("Du hast nicht genug Geld!")

    if amount<0:
        await ctx.send("Der Betrag muss eine positive Zahl sein!")

    await update_bank(ctx.author,-1* amount)
    await update_bank(ctx.author, amount, "bank")

    await ctx.send(f"Du hast {amount} Moneten auf deine Bank gelegt")

Here's the Error:

Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site- 
packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site- 
packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site- 
packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an Exception: 
TypeError: 'Member' object does not support indexing

Read more here: https://stackoverflow.com/questions/66336165/discord-py-deposit-command-in-economy-system-bot-doesnt-work-properly

Content Attribution

This content was originally published by m4ximpl4yz at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: