我试着用我的discord.py机器人做一个经济型的小游戏。 我将人的平衡保存在不同的文本文件中(bot是给我和其他3个朋友的)
现在,如果它读取文件并需要将两个数字相加作为变量,它会说: discord.ext.commands.errors.CommandInvokeError:命令引发异常:TypeError:int()参数必须是字符串、类似于对象的字节或数字,而不是“\u io.TextIOWrapper”
我希望它以数字形式读取文件
这是我的代码:
async def beg(ctx):
file = open(ctx.author.name, 'w')
number = ("10","25","69","75","100")
begmoney = (random.choice(number))
balance = open(ctx.author.name, "r")
newmoney = begmoney + int(balance)
await ctx.send(newmoney)
file.write(newmoney)
await ctx.send("you got " + begmoney )
await ctx.send("your balance now is: " + file.read())
有人能帮我吗
从代码中我得到的是,你试图得到一个随机数,并将其添加到文件中的余额中,然后将新的金额写回。 这是你应该做的吗:
相关问题 更多 >
编程相关推荐