简体   繁体   中英

How to fix the Type error: unsupported operand type(s) for +: 'function' and 'int'?

I'm trying to make a weird potato counter with discord.py and save it to.json file.

Code is below:

@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!')

but it gives me this error:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: unsupported operand type(s) for +: 'function' and 'int'

The error message rather clearly states you're trying to add ( + ) a function ( bal I would guess) and an int , and you can't do that.

So don't do that? Maybe call the function or something? Since you don't provide all the code, let alone in a runnable / replicable state, it's difficult to provide more help than that.

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