T
T
tooohell2021-08-05 21:55:43
Python
tooohell, 2021-08-05 21:55:43

How to check the message for an integer from the database so that the bot does not crash?

The essence of the question is that in my code there is a game of heads or tails, and when the user writes the amount after the side of the coin, the following actions take place. BUT if instead of the amount you write the amount + something else, then the bot crashes and gives an error. in general, you need to make some kind of check so that when you write not a number or a number with letters / symbols, he says that the amount is not correct. I also tried (I'm still a beginner) to do something like if stavka != int then a message is sent that the amount is not correct, as a result, when writing any amount, it always showed that it was not correct ........
.

elif "/решка" in msg.lower():
          db = sqlite3.connect('server4.db')
          db.row_factory = sqlite3.Row
          cursor = db.cursor()
          stavkat = msg.lower().split('/решка ')[-1]
          cursor.execute(f"UPDATE users SET stavka={stavkat} WHERE user_id = {user_id}")
          flip = random.randint(1, 2)	
          if stavkat != int:
            sender(id, "Веддите коректное число!")
          else:
            for mm in cursor.execute(f"SELECT money, stavka FROM users WHERE user_id = {user_id}"):
              if mm['stavka'] > mm['money']:
                sender(id, f"У вас недостаточно средств!\n\nТекущий баланс:{mm['money']}")
                cursor.execute(f"UPDATE users SET stavka = 0 WHERE user_id = {user_id}")
              else:
                if flip == 2:
                  cursor.execute(f"UPDATE users SET stavka = {stavkat} WHERE user_id = {user_id}")
                  for m in cursor.execute(f"SELECT money, stavka FROM users WHERE user_id = {user_id}"): 
                    cursor.execute(f"UPDATE users SET money = money+{m['stavka']} WHERE user_id = {user_id}")
                    sender(id, f"РЕШКА\n @id{user_id}({fullname}) Выиграл {stavkat}")
                    cursor.execute(f"UPDATE users SET stavka = 0 WHERE user_id = {user_id}")
                    for m2 in cursor.execute(f"SELECT money FROM users WHERE user_id = {user_id}"):
                      sender(id, f"Текущий баланс:{m2['money']}")
                else:
                  cursor.execute(f"UPDATE users SET stavka = {stavkat} WHERE {user_id}")
                  for mmm in cursor.execute(f"SELECT money, stavka FROM users WHERE user_id = {user_id}"):
                    cursor.execute(f"UPDATE users SET money = money-{mmm['stavka']} WHERE user_id = {user_id}")
                    sender(id, f"РЕШКА\n @id{user_id}({fullname}) Проиграл {stavkat}")
                    cursor.execute(f"UPDATE users SET stavka = 0 WHERE user_id = {user_id}")
                    for mmm2 in cursor.execute(f"SELECT money FROM users WHERE user_id = {user_id}"):
                      sender(id, f"Текущий баланс:{mmm2['money']}")
            db.commit()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-08-05
@toohell

String method isdigit()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question