繁体   English   中英

无法解决:TypeError: 'NoneType' object is not iterable

[英]unable to solve : TypeError: 'NoneType' object is not iterable

@plugin.command
@lightbulb.command('inv', "player inventory", aliases = ['inventory'])
@lightbulb.implements(lightbulb.PrefixCommand)
async def inv(ctx : lightbulb.context):
    animal_list = [None,"🦊Fox", "🐺Wolf", "🐱Cat", "🦝Raccoon", "🐯Tiger", "🦁Lion", "🐆Leopard","🦌Deer", "🦓Zebra", "🦄Unicorn"]
    tools_list = [None, "🔫Rifle", "🎣Rod", "⛏Pick"]

    db = sqlite3.connect("eco.sqlite")
    cursor = db.cursor()

    cursor.execute(f'SELECT * FROM animals WHERE user_id = {ctx.author.id}')
    animals = cursor.fetchone()
    cursor.execute(f'SELECT * FROM tools WHERE user_id = {ctx.author.id}')
    tools = cursor.fetchone()

    animals_ = [f"{i} x{j}" for i, j in itertools.zip_longest(animal_list, animals) if j> 0 and j < 2]
    tools_ = [f"{i} x{j}" for i, j in itertools.zip_longest(tools_list, tools) if j> 0 and j < 2]

    animals_ = "\n".join(animals_) if len(animals_) > 0 else "***No animals in Inventory***"
    tools_ = "\n".join(tools_) if len(tools_) > 0 else "***No tools in Inventory***"

    emb = hikari.Embed(title = "Inventory", description = f"All your collected stuff", colour = "#50a45c")
    emb.add_field(name = "Animals", value = animals_)
    emb.add_field(name = "Tools", value = tools_)

    await ctx.respond(embed = emb)

    db.commit()
    cursor.close()
    db.close()

不断出现错误TypeError: 'NoneType' object is not iterable

回溯错误:

Traceback (most recent call last):
  File "C:\Users\HP\Desktop\discord bot\env\lib\site-packages\lightbulb\app.py", line 1038, in handle_message_create_for_prefix_commands
    await self.process_prefix_commands(context)
  File "C:\Users\HP\Desktop\discord bot\env\lib\site-packages\lightbulb\app.py", line 1010, in process_prefix_commands
    await context.invoke()
  File "C:\Users\HP\Desktop\discord bot\env\lib\site-packages\lightbulb\context\base.py", line 311, in invoke
    await self.command.invoke(self)
  File "C:\Users\HP\Desktop\discord bot\env\lib\site-packages\lightbulb\commands\prefix.py", line 119, in invoke
    await self(context, **kwargs)
  File "C:\Users\HP\Desktop\discord bot\env\lib\site-packages\lightbulb\commands\base.py", line 605, in __call__
    return await self.callback(context, **kwargs)
  File "c:\Users\HP\Desktop\discord bot\extensions\economy\inventory.py", line 23, in inv
    animals_ = [f"{i} x{j}" for i,j in itertools.zip_longest(animal_list, animals) if j> 0 and j <2]
TypeError: 'NoneType' object is not iterable

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

Traceback (most recent call last):
  File "C:\Users\HP\Desktop\discord bot\env\lib\site-packages\lightbulb\app.py", line 1057, in handle_message_create_for_prefix_commands


animals = None 检查cursor.fetchone()的结果并确保它返回了一些东西。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM