Python 如何修复类型错误:+;的操作数类型不受支持:';功能';和';int';?
我正试图用discord.py创建一个奇怪的马铃薯计数器,并将其保存到.json文件中 代码如下:Python 如何修复类型错误:+;的操作数类型不受支持:';功能';和';int';?,python,discord.py,discord.py-rewrite,Python,Discord.py,Discord.py Rewrite,我正试图用discord.py创建一个奇怪的马铃薯计数器,并将其保存到.json文件中 代码如下: @client.command() async def get(ctx): with open('get.json', 'r') as f: get = json.load(f) get[str(ctx.author.id)] = bal + 1 with open('get.json', 'w') as f: json.dump(get
@client.command()
async def get(ctx):
with open('get.json', 'r') as f:
get = json.load(f)
get[str(ctx.author.id)] = bal + 1
with open('get.json', 'w') as f:
json.dump(get, f, indent=4)
await ctx.send('You got 1 potato!')
但它给了我一个错误:
discord.ext.commands.errors.CommandInvokeError:Command引发了一个异常:TypeError:+:“function”和“int”的操作数类型不受支持错误消息相当清楚地表明您正在尝试添加(++
)一个函数(bal
)和一个int
,而您不能这样做
所以不要这样做?也许调用函数或其他什么?由于您没有提供所有代码,更不用说处于可运行/可复制状态,因此很难提供比这更多的帮助。在bal+1
中,什么是bal
?