-4

I keep trying, it was a tutorial. I did exactly what it said. I doubt the next episode will say what's wrong. why do i need so many words ,,,

@client.command()
async def balance(ctx):
  await open_account(ctx.author)
  user = ctx.author
  users = get_bank_data()

  wallet_amt = users[str(user.id)]["wallet"]
  bank_amt = users[str(user.id)]["bank"]

  em = discord.Embed(title = f"{ctx.author.name}'s balance",color=discord.color.dark_green)
  em.add_field(name = "Wallet Balance", value = wallet_amt)
  em.add_field(name = "Bank Balance", value = bank_amt)
  await ctx.send(embed=em)

@client.command()
async def beg(ctx):
  await open_account(ctx.author)

  users = get_bank_data()

  user = ctx.author

  earnings = random.randrange(51)


  await ctx.send(f"Someone gave you {earnings} coins!!")

  users[str(user.id)]["wallet"] += earnings

  with open("bank.json", "w") as f:
    json.dump(users, f)


def open_account(user):

  users = await get_bank_data()

  with open("bank.json", "r") as f:
    users = json.load(f)

    if str(user.id) in users:
      return False
    else:
      users[str(user.id)] = {}
      users[str(user.id)]["wallet"] = 0
      users[str(user.id)]["bank"] = 0

    with open("bank.json", "w") as f:
      json.dump(users, f)
    return True

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

  return users

but with this error

z:\DBot\bot(1.2).py:108: RuntimeWarning: coroutine 'Command.__call__' was never awaited
  with open("bank.json", "r") as f:
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

i don't know what to do. Sorry my questions are bad because i just want someone to answer them, dont have time to make them good

Tree Jin
  • 1
  • 1
  • 2
    Does this answer your question? [Learning asyncio: "coroutine was never awaited" warning error](https://stackoverflow.com/questions/54441424/learning-asyncio-coroutine-was-never-awaited-warning-error) – Andrew Oct 07 '21 at 05:10
  • @Andrew If you look at the error message, your post is not really helpful. I have watched the same tutorial and there is no need to `await` the things mentioned in the error message. – Dominik Oct 07 '21 at 06:44
  • I do not know if that helps, but maybe put your functions on top of the code, so they are accessible. – Dominik Oct 07 '21 at 06:44

1 Answers1

1

open_account() and get_bank_data() are not required be asynchronous functions, You can use def open_account(user) and def get_back_data().

If you do that, you should remove await while calling those two functions.

Roxx
  • 314
  • 1
  • 6