I have made a system that uses JSON files to create a currency system with a discord bot using discord.py I want users to be able to do b,balance to show them how much they have, or b,balance {user} in order to check someone else's balance. I tried the code and I got an error saying that the argument member is not passed even when I have passed it... Thanks for your help!
Code:
@client.command(aliases=["bal", "Bal", "BAL"])
async def balance(ctx, member:discord.Member= None):
await open_account(ctx.author)
await open_account(member)
user = ctx.author
users = await get_bank_data()
wallet_amt = users[str(user.id)]["Wallet"]
bank_amt = users[str(user.id)]["Bank"]
wallet_member = users[str(member.id)]["Wallet"]
bank_member = users[str(member.id)]["Bank"]
if member is None:
member = ctx.message.author
else:
em2 = discord.Embed(title=f"{member.name}'s Balance", color=discord.Color.blue())
em2.add_field(name="Wallet", value=wallet_member)
em2.add_field(name="Bank", value=bank_member)
await ctx.send(embed=em2)
Output:
Ignoring exception in command balance:
Traceback (most recent call last):
File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\EKTA\Desktop\Aarush\Python\My Bot\main.py", line 156, in balance
await open_account(member)
File "c:\Users\EKTA\Desktop\Aarush\Python\My Bot\main.py", line 264, in open_account
if str(user.id) in users:
AttributeError: 'NoneType' object has no attribute 'id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Python39\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Python39\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: AttributeError:
'NoneType' object has no attribute 'id'