I have and problem with my code. It is a part of mine command for discored bot, but it fails to write anything inside file with no error
item = "Scrap Metal"
price = 0.56 #per gram
cost = grams * price
cost = round(cost)
human = random.randrange(1, 3)
if human == 1:
human = "Chinese web store"
elif human == 2:
human = "TechKnow scrap yard"
elif human == 3:
human= "Random guy on the street"
embed = discord.Embed(title="You went mining!", description=f"You have found **{grams}g** of **{item}**.\n\nYou sold it to **{human}** for **{cost}**!", color=0x00ffee)
await ctx.channel.send(embed=embed)
try:
f = open(f"./all/users/{ctx.author.id}/balance.txt", "r ")
a = f.read()
int(a)
f.close()
except:
a = 0
i = cost
i = a i
str(i)
f = open(f"./all/users/{ctx.author.id}/balance.txt", "w ")
f.seek(0)
f.write(i)
f.close()
Thank you for your help upfront
CodePudding user response:
Your code contains statements that should throw an errors. Here are at least some of them:
str(i)
should be replaced toi = str(i)
. Without this, the script tries to writei
as a number to the file and throwsTypeError: write() argument must be str, not int
int(a)
should be replaced bya = int(a)
when you read the file. OtherwiseTypeError: can only concatenate str (not "int") to str
will be thrown when you tryi = a i
If you don't get any errors, then make sure that this code runs at all.