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
@client.command()
async def deposit(ctx,amount = None):
if amount == None:
await ctx.send("Bitte gebe den Betrag an!")
return
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!")
return
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
You must have forgotten to open the account at the beginning of your deposit
command.
async def deposit(ctx, amount=None):
await open_account(ctx.author)
You also forgot to add a return
after if amount > bal[0]:
.
if amount > bal[0]:
await ctx.send("**You do not have enough money to do this!**")
return
Also your update_bank
seems to have a mistake. You need to return bal
at the end, not user
. In your case:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.