0

在控制台中,它给了我“库存”没有“搜索”命令的错误,但正如您从图像中看到的那样,“库存”是数据库的表,当我尝试执行“插入、搜索、更新”时“它给了我同样的错误。你能帮助我吗?

错误:

  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'

代码1:

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

代码2:

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")
4

0 回答 0