Answer the question
In order to leave comments, you need to log in
Why doesn't the bot execute the command again?
the bot gives the characteristics of the tanks, the bot does everything right at the first request.
import telebot
import random
from telebot import types
import sqlite3
from sqlite3 import Error
from time import ctime
bot = telebot.TeleBot('')
t26 = open('C:\\Users\\User\\Desktop\\Bot_WotBlitz\\R09_T-26.png', 'rb')
bt2 = open('C:\\Users\\User\\Desktop\\Bot_WotBlitz\\r08_bt-2_image_resized.png', 'rb')
bt7 = open('C:\\Users\\User\\Desktop\\Bot_WotBlitz\\r03_bt-7_image_resized.png', 'rb')
a20 = open('C:\\Users\\User\\Desktop\\Bot_WotBlitz\\r12_a-20_image_resized.png', 'rb')
Sy85B = open('C:\\Users\\User\\Desktop\\Bot_WotBlitz\\GAZ-74b.png', 'rb')
def post_sql_query(sql_query):
with sqlite3.connect('C:\\Users\\User\\Desktop\\Bot_WotBlitz\\bazaa.db') as connection:
cursor = connection.cursor()
try:
cursor.execute(sql_query)
except Error:
pass
result = cursor.fetchall()
return result
def register_user(user_id, username, first_name, last_name):
user_check_query = f'SELECT * FROM USERS WHERE user_id = {user_id};'
user_check_data = post_sql_query(user_check_query)
if not user_check_data:
insert_to_db_query = f'INSERT INTO BAZA (user_id, username, first_name, last_name) VALUES ({user_id}, "{username}", "{first_name}", "{last_name}", "{ctime()}");'
post_sql_query(insert_to_db_query)
def user_exists(self, user_id):
if self.get_user_name(user_id) is None:
return False
return True
def start(m, res=False):
register_user(m.from_user.id, m.from_user.username, m.from_user.first_name, m.from_user.last_name)
conn = sqlite3.connect('C:\\Users\\User\\Desktop\\Bot_WotBlitz\\bazaa.db', check_same_thread=False)
cursor = conn.cursor()
def get_user_name(self, user_id):
result = self.cursor.execute('SELECT name FROM USERS WHERE id = ?', (user_id,)).fetchone()
if result is None:
return None
return result[0]
def db_table_val(user_id: int, username: str, first_name: str, last_name: str):
cursor.execute('INSERT INTO BAZA (user_id, username, first_name, last_name) VALUES (?,?,?,?)', (user_id, username, first_name, last_name))
conn.commit()
def bd(m):
us_id = m.from_user_id
us_name = m.from_user.username
firstname = m.from_user.first_name
lastname = m.from_user.last_name
db_table_val(user_id=us_id, username=us_name, first_name=firstname, last_name=lastname)
conn.commit()
@bot.message_handler(commands=['start'])
def get_text_messages(m, res=False):
markup=types.ReplyKeyboardMarkup(resize_keyboard=False)
item1=types.KeyboardButton('Найти танк')
item2=types.KeyboardButton('Профиль')
markup.add(item1, item2)
bot.send_message(m.chat.id, f'Добро пожаловать {m.from_user.first_name}', reply_markup=markup)
bot.send_message(m.chat.id, 'Чтобы найти танк, нажми на кнопку ниже\n\nВажно чтобы название танка было точное!', reply_markup=markup)
@bot.message_handler(content_types=["text"])
def language (message, res=False):
if message.text.strip() == 'Найти танк' :
a = telebot.types.ReplyKeyboardRemove()
bot.send_message(message.chat.id, 'Введите название танка:', reply_markup=a)
if message.text.strip() == 'Т-26' :
bot.send_photo(message.chat.id, (t26))
bot.send_message(message.chat.id, '<======Т-26======>\n\nМасса (т) - 9.26\n\nПрочность - 270 ед.\n\nМощность двигателя (л.с.) - 130\n\nМаксимальная скорость (км/ч) - 36\n\nБронепробиваемость базовым снарядом (мм) - 37-51\n\nУрон базовым снарядом - 26-44\n\nСкорострельность орудия (выстр/мин) - 10.3')
if message.text.strip() == 'БТ-2' :
bot.send_photo(message.chat.id, (bt2))
bot.send_message(message.chat.id, '<======БТ-2======>\n\nМасса (т) - 12.93\n\nПрочность - 380 ед.\n\nМощность двигателя (л.с.) - 350\n\nМаксимальная скорость (км/ч) - 44\n\nБронепробиваемость базовым снарядом (мм) - 37-51\n\nУрон базовым снарядом - 38-63\n\nСкорострельность орудия (выстр/мин) - 11.8')
if message.text.strip() == 'БТ-7' :
bot.send_photo(message.chat.id, (bt7))
bot.send_message(message.chat.id, '<======БТ-7======>\n\nМасса (т) - 15.34\n\nПрочность - 470 ед.\n\nМощность двигателя (л.с.) - 375\n\nМаксимальная скорость (км/ч) - 45\n\nБронепробиваемость базовым снарядом (мм) - 48-64\n\nУрон базовым снарядом - 45-75\n\nСкорострельность орудия (выстр/мин) - 13.0')
if message.text.strip() == 'А-20' :
bot.send_photo(message.chat.id, (a20))
bot.send_message(message.chat.id, '<======А-20======>\n\nМасса (т) - 18.57\n\nПрочность - 520 ед.\n\nМощность двигателя (л.с.) - 400\n\nМаксимальная скорость (км/ч) - 45\n\nБронепробиваемость базовым снарядом (мм) - 71-97\n\nУрон базовым снарядом - 90-150\n\nСкорострельность орудия (выстр/мин) - 7.8')
if message.text.strip() == 'СУ-85Б' :
bot.send_photo(message.chat.id, (Sy85B))
bot.send_message(message.chat.id, '<======СУ-85Б======>\n\nМасса (т) - 12.58\n\nПрочность - 500 ед.\n\nМощность двигателя (л.с.) - 400\n\nМаксимальная скорость (км/ч) - 45\n\nБронепробиваемость базовым снарядом (мм) - 71-97\n\nУрон базовым снарядом - 90-150\n\nСкорострельность орудия (выстр/мин) - 7.8')
elif message.text.strip() == 'Профиль' :
bot.send_message(message.chat.id, f'<======Ваш профиль======>\n\nИмя: {message.from_user.first_name}\nАйди: {message.from_user.id}')
bot.polling(none_stop=True, timeout=123)
Answer the question
In order to leave comments, you need to log in
Maybe because you don't remove webhooks try writing this at the end
bot.remove_webhook()
bot.polling(none_stop=True, timeout=123)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question