F
F
Flener2022-04-21 22:00:38
Python
Flener, 2022-04-21 22:00:38

Search mongodb for the $lte operator. Discord.py fails, why?

Function to buy a temporary role.
It works on the principle:
A person buys a role, indicating the period for which he buys the role.
The bot checks the user's balance and the cost of the role.
Multiplies by the number of days - a discount for a long period
And writes all this data to a separate database

After that, every 3 minutes the bot must check the entire database for expired roles and remove them.
The problem is that when I use the $lte operator the visual studio code says there is an error and says nothing will work. He swears specifically at the $ sign. Without this sign, he stops swearing, but he doesn’t know what lte stands for and I don’t think it will work like that, you see, for the database this is no longer an operator.

Please tell me how to use this operator.

And what do you think, will there be any problems if the bot finds 2-3 users with an expired role?
Or will it be necessary to do a separate task for each found record?

@client.command(
    name = "buy",
    aliases = ["купить", "regbnm", "Купить", "бай", "Regbnm"],
    brief = "Купить роль",
    usage = "!купить <@role> <Количество дней>"
)
async def buy(ctx, role, days=1):
    if role == None:
        ctx.send("Вы не указали роль!")
        return
    tme = days * 86400
    tim = time.time()
    if days >= 7:
        day = days * 0.9
    if days >= 14:
        day = days * 0.8
    if days >= 30:
        day = days * 0.75
    else:
        day = days
    timeend = tim + tme
    author = ctx.author
    post = {
        "roleid": role.id,
        "member": author.id,
        "timeb": tim,
        "timeend": timeend
    }
    datar = collrole.find_one({"role": role})
    datau = colluser.find_one({"_id": author.id})
    if datar["trade"] == False:
        ctx.send("Данная роль не на продаже!")
        return
    balance = datau["bal"]
    pricerole = datar["price"]
    price = pricerole * day
    if balance <= price:
        ctx.send("У вас не хватает *****")
        return
    colluser.update_one({"_id": author.id},
        {"$set": {"bal": balance - price}})
    collrt.insert_one(post)
    await client.add_roles(author, role)
    await ctx.message.add_reaction("✅")

@tasks.loop(minutes=3)
async def role_check(ctx):
    timenow = time.time()
    collrt.find({"timeend": {$lte:f"{timenow}"}})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TheMade, 2022-04-22
@TheMade

"$lte" is not a variable.
It must be enclosed in quotation marks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question