Home > OS >  why does it keep saying "TypeError: '<=' not supported between instances of '
why does it keep saying "TypeError: '<=' not supported between instances of '

Time:08-21

this is the full error of the code

i would really love the help



mainshop = [{"name":"Time_watch","price":1000,"description":"Resets certain cooldowns (limited uses)(WIP)"}, {"name":"Gun","price":10000,"description":"A better way to rob people with a shorter cooldown!"}, {"name":"Guhhh Placeholder!!","price":10000000,"description":"I sure love placeholders"}]
@client.command()
@commands.is_owner()
async def shop(ctx):#real#:troll:.name
    em = discord.Embed(title = "Shopping District")

    for item in mainshop:
      name = item["name"]
      price = item["price"]
      desc = item["description"] #i do believe its because you have like no DESCRIPTION in the item list thing
      #get fake
      em.add_field(name = name, value = f"${price} | {desc}")
#real
    await ctx.send(embed = em)

import discord
from discord.ext import commands
import asyncio
import os
import json
 
##### START LEVEL COMMAND #####


@client.command(name='bal')
async def balance(ctx, user:discord.Member=None):
    colour = randint(0, 0xffffff)
    await open_account(ctx.author)
    if user is None:
        user = ctx.author
    users = await get_bank_data()
    wallet_amt = users[str(user.id)]["wallet"]
    bank_amt = users[str(user.id)]["bank"]
    em = discord.Embed(title=f"{user}'s balance", color=colour)
    em.add_field(name="Wallet", value=wallet_amt)
    em.add_field(name="Bank", value=bank_amt)
    await ctx.send(embed=em)

async def buy_this(user,item_name,amount):
    item_name = item_name.lower()
    name_ = None
    for item in mainshop:
        name = item["name"].lower()
        if name == item_name:
            name_ = name
            price = item["price"]
            break

    if name_ == None:
        return [False,1]

    cost = price*amount

    users = await get_bank_data()

    bal = await update_bank(user)#r.i.p. KB's confindince

    if bal[0]<= cost:
        return [False,2]


    try:
        index = 0
        t = None
        for thing in users[str(user.id)]["bag"]:
            n = thing["item"]
            if n == item_name:
                old_amt = thing["amount"]
                new_amt = old_amt   amount
                users[str(user.id)]["bag"][index]["amount"] = new_amt
                t = 1
                break
            index =1 
        if t == None:
            obj = {"item":item_name , "amount" : amount}
            users[str(user.id)]["bag"].append(obj)
    except:
        obj = {"item":item_name , "amount" : amount}
        users[str(user.id)]["bag"] = [obj]        

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

    await update_bank(user,cost*-1,"wallet")

    return [True,"Worked"]

@client.command()
async def buy(ctx,item,amount):#how come these arent definded no more? oh I prollydid smth by mistake guhhhhhhh
        res = await buy_this(ctx.author,item,amount) 

        if not res[0]:
         if res[1]==1:
            await ctx.send("That is not an item in shop")
            return
         if res[1]==2:
            await ctx.send(f"You don't have enough money to buy the {amount}")
            return
            await ctx.send(f"Successfully bought {amount}: {item}")



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

    try: 
        bag = users[str(user.id)]["bag"]
    except: 
        bag = []


    em = discord.Embed(title = "Bag")
    for item in bag: 
        name = item["item"]
        amount = item["amount"]

        em.add_field(name = name, value = amount)

    await ctx.send(embed = em)
 #Oh you mean this ? oh yeah Idk what I put that there



async def open_account(user):
  
    users = await get_bank_data()

    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("mainbank.json", "w") as f:
        json.dump(users, f)
      
    return True




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 bal




the code that should matter. I do not understand at all what is wrong with the code. I used this code before no errors. So if anyone could please explain that would be greatly appreciated. I have tried putting this in its own thing. it didnt work still. i have also tried putting if bal <= int(cost) this also didnt work.

CodePudding user response:

on the line if bal[0]<= cost: if you cast to an integer int(bal[0]) it should be comparing two integers then, and vice-versa if cost is a string

CodePudding user response:

Cost is already an int, looks like bal[0] is a string. Try int(bal[0]) <= cost instead (or float(bal[0]) if it has decimals)

  • Related