简体   繁体   中英

“TypeError: unhashable type: 'set'” for python discord bot

I am making a discord bot using python and its saying "TypeError: unhashable type: 'set'". I cant figure out why:/

def withdraw(person,amount,ininventory,allmoney):
  amount = int(amount)
  if person in allmoney.keys():
    if allmoney[person] > amount:
      if person in ininventory.keys():
        ininventory[person] += amount
        allmoney[person] -= amount
      else:
        ininventory[person] = 0
        ininventory[person] += amount
        allmoney[person] -= amount
      return ininventory[person],allmoney[person],allmoney,ininventory
    else:
      moneynow = allmoney[person]
      allmoney[person] = 0
      return ininventory[person],moneynow,allmoney,ininventory
  else:
    ininventory[person] = 0
    return 0,allmoney[person],allmoney,ininventory

"if person in allmoney.keys():" is what its saying "TypeError: unhashable type: 'set'" for

and this is whats calling the function.

allmoney = {}
ininventory = {}
@client.command()
async def withdraw(ctx, arg):
  global allmoney
  global ininventory
  amountpocket = "broken"
  amountbank = "broken"
  amountpocket,amountbank,allmoney,ininventory = bank.withdraw({ctx.author.name},arg,allmoney,ininventory)
  await ctx.send(f'withdrawed {arg} Dollars!\nYou now have {amountpocket} Dollars in your pocket!\nYou now have {amountbank} in your account!')

this is the calling

amountpocket,amountbank,allmoney,ininventory = bank.withdraw({ctx.author.name},arg,allmoney,ininventory)

I'm sorry if this is not the proper way to ask the questions but i dont know how to use this sight and im new to it.

My last question got shut down i think.

Verify the data type of allmoney . Unhashable type set means that you are treating a set as if it was a dictionary. Sets do not have keys thus calling allmoney.keys() will give an error. Sets are like arrays which only contain values.

example_set = {"apple", "orange", "pineapple"}

example_dict = {"fruit": "apple", "vegetable": "lettuce"}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM