Answer the question
In order to leave comments, you need to log in
How to check if a list is empty in MongoDB?
(I use: MongoDB, Python and Discord.py)
How to check if a list is empty? I tried to do it, but for some reason the bot sends an empty message when the list is empty.
@bot.command()
async def test(ctx):
products = collection.find_one({"_id": ctx.author.id})["products"]
if products == None:
msg = "Пусто"
else:
msg = products
await ctx.send("Продукты:", msg)
Answer the question
In order to leave comments, you need to log in
If you need to check the list for emptiness, then instead of:
if products == None:
msg = "Пусто"
if not products:
msg = "Пусто"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question