The command is needed to take away the server balance from users in a certain amount (if they got it somehow/bug), but the bot ignores all values ​​except amount== 'all'. who can help? I will be very grateful.


async def take(ctx, member: discord.Member, amount=None):
    if amount== "all":
        cursor.execute("UPDATE users SET cash= ? WHERE id= ? AND guild_id= ?", (0, member.id, ctx.guild.id,))
    elif int(amount) < one:
        await ctx.send("Sum must not be less than 1")
    elif not amount.is_digit():
        await ctx.send("Must be sum or all")
        cursor.execute("UPDATE users SET cash= cash -? WHERE id= ? AND guild_id= ?", (amount, member.id, ctx.guild.id,))
    await ctx.send(f'{ctx.author} took away {member} {amount} rubles from the user')

how is the value of all passed? digit or 'all' ?

Anatoly Kritskiy2022-02-06 10:13:21

the value of all is passed as 'all'

Marcus2022-02-06 10:19:33

in the first if I understood not 'None', but 'all'? I think the problem is that when you send some value, you pass a text value to the SQL query, try passing int (amount)

Anatoly Kritskiy2022-02-06 10:22:09

unfortunately that didn't help either.

Marcus2022-02-06 10:55:40

The error may be that is_digit() is written with an underscore. A string (if amount is a string) has an isdigit() method. An exception occurs when calling a non-existent method and the "kirdyk" function. Well, it’s not specifically related to the question, but the check elif not amount.is_digit () should be swapped with elif int (amount) < 1. Yes, and checking amount for None is not visible (or why give this parameter a value according to default?).

GrAnd2022-02-06 11:10:42