Answer the question
In order to leave comments, you need to log in
When I write .casino 18 when my balance is 17, he does not write to me that there are not enough funds. How to fix and the console does not give an error?
@client.command(aliases = ['casino','777','казино'])
async def __casino(ctx, amount = None):
if amount is None:
await ctx.send(f'Укажите кол-во {gem} которое хотите поставить')
else:
if amount < 10:
await ctx.send(f'Минимальная ставка 10{gem}')
else:
if amount > 50:
await ctx.send(f'Максимальная ставка 50{gem}')
else:
if cursor.execute("SELECT gems from users where id = {}".format(ctx.author.id)).fetchone() < {amount}:
await ctx.send(f"**{ctx.author}**, у вас недостаточно {gem} для ставки")
else:
randomka = (random.randint(1,100))
cursor.execute("UPDATE users set gems = gems - {} where id = {}".format(amount, ctx.author.id))
if randomka > 60:
cursor.execute("UPDATE users set gems = gems + 2 * {} where id = {}".format(amount, ctx.author.id))
await ctx.send(f"Вы выиграли {2 * {amount}}")
else:
await ctx.send(f'Вы проиграли')
Answer the question
In order to leave comments, you need to log in
all the guys thanks, I understood but no one helped me because there it was necessary to put fetchone()[0] < (int(amount) and replace amount with int(amount) everywhere
Perhaps the reason is an uncommitted transaction.
You have the following code cursor.execute("UPDATE users
In theory, after any update, you need to call connection.commit() - commit the transaction.
If this is not done, then the player's balance will not change with wins and losses.
Well, because of this, checking for exceeding the limit does not work because there is actually no limit exceeding.
Well, the balance check code is strange, coursor.execute("select returns a tuple or None, and you compare it with set judging by the code. It’s
better to rewrite the query and pass parameters not through string formatting, so that if something does not catch sql injection.Try the
string:
if cursor.execute("SELECT gems from users where id = {}".format(ctx.author.id)).fetchone() < {amount}:
Rewrite
if not cursor.execute("SELECT 1 FROM users WHERE id = ? AND gems >= ?), (ctx.author.id, amount)).fetchone():
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question