Reputation: 21
@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()
Keep Getting Error : TypeError: 'NoneType' object is not iterable
Traceback Error:
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
Upvotes: 2
Views: 282
Reputation: 1668
animals = None
. Check the result of cursor.fetchone()
and make sure that it returns something.
Upvotes: 2