tinydb search,insert,update errors

108 Views Asked by At

in the console it gives me the error that "inventory" does not have the "search" command but as you can see from the images "inventory" is a table of the db and also when I try to do "insert, search, update" it gives me the same error. Can you help me?

error:

  File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\user\OneDrive\Desktop\DiscordBots\bot\TestBot\testbot.py", line 81, in find
    result = inventory.search(Inventory.name == "common_square")
AttributeError: 'Command' object has no attribute 'search'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Command' object has no attribute 'search'

code1:

db = TinyDB('testdb.json')
Database = Query()
Inventory = Query()
inventory = TinyDB.table(db,'inventory')

code2:

if c_cards_rdm == 2:
                image = 'https://cdn.discordapp.com/attachments/873309423555194910/873309521693536306/common_square.png'
                result = inventory.search(Inventory.name == "common_square")
                if str(result) == '[]':
                    inventory.insert({"name":"common_square","quantity":"1","atk":"0","def":"35"})
                else:
                    inventory.update({"quantity":f"{str(int(result[0]['quantity'])+1)}"}, 
                    Inventory.name == "common_square")
0

There are 0 best solutions below