Помощь по боту для тг

alexa007x

Новичок
Пользователь
Июл 15, 2024
4
0
1
Всем добрый день. Подскажите почему при нажатии на кнопку "Посмотреть время" вылезает сообщение "Как дела?"
Код:
import telebot

import config

import random

import datetime



from telebot import types

from datetime import date



bot = telebot.TeleBot(config.TOKEN)



current_date = date.today()



current_date_time = datetime.datetime.now()

current_time = current_date_time.time()



@bot.message_handler(commands=['start'])

def welcome(message):

    sti = open('static/welcome.webp', 'rb')

    bot.send_sticker(message.chat.id, sti)



    # keyboard

    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)

    item3 = types.KeyboardButton("Посмотреть дату и время")

    item1 = types.KeyboardButton("Рандомное число")

    item2 = types.KeyboardButton("Как дела?")



    markup.add(item1, item2, item3)



    bot.send_message(message.chat.id, "Добро пожаловать, {0.first_name}!\nЯ - {1.first_name}, создан чтобы быть тестовым ботом.".format(message.from_user, bot.get_me()),

        parse_mode='html', reply_markup=markup)



@bot.message_handler(content_types=['text'])

def lalala(message):

    if message.chat.type == 'private':

        if message.text == 'Рандомное число':

            bot.send_message(message.chat.id, str(random.randint(0,100)))

        elif message.text == 'Посмотреть дату и время':



            markup = types.InlineKeyboardMarkup(row_width=2)

            item1 = types.InlineKeyboardButton("Посмтреть время", callback_data='timenow')



            markup.add(item1)



            bot.send_message(message.chat.id, str(current_date),  reply_markup=markup)

        elif message.text == 'Как дела?':



            markup = types.InlineKeyboardMarkup(row_width=2)

            item1 = types.InlineKeyboardButton("Хорошо", callback_data='good')

            item2 = types.InlineKeyboardButton("Не очень", callback_data='bad')



            markup.add(item1, item2)



            bot.send_message(message.chat.id, 'Отлично, сам как?', reply_markup=markup)

        else:

            bot.send_message(message.chat.id, 'Я не знаю что ответить')



@bot.callback_query_handler(func=lambda call: True)

def callback_inline(call):

    try:

        if call.message:

            if call.data == 'good':

                bot.send_message(call.message.chat.id, 'Вот и отличненько')

            elif call.data == 'bad':

                bot.send_message(call.message.chat.id, 'Бывает')



            # remove inline buttons

            bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Как дела?",

                reply_markup=None)



            # show alert

            bot.answer_callback_query(callback_query_id=call.id, show_alert=False,

                text="Вы нажали на инлайн-кнопку")



    except Exception as e:

        print(repr(e))





@bot.callback_query_handler(func=lambda call: True)

def whattimenow(wtn):

    try:

        if call1.message:

            if wtn.data == 'timenow':

                bot.send_message(call.message.chat.id, str(current_time))



            # remove inline buttons

            bot.edit_message_text(chat_id=call1.message.chat.id, message_id=call1.message.message_id, text="Посмотреть дату и время",

                reply_markup=None)



            # show alert

            bot.answer_callback_query(callback_query_id=call1.id, show_alert=False,

                text="Вы нажали на инлайн-кнопку")



    except Exception as e:

        print(repr(e))



#RUN

bot.polling(none_stop=True)
 
Последнее редактирование:

regnor

Модератор
Команда форума
Модератор
Июл 7, 2020
2 639
472
83
 

alexa007x

Новичок
Пользователь
Июл 15, 2024
4
0
1
хорошо, а что вы имели ввиду про ошибку в коде?
 

alexa007x

Новичок
Пользователь
Июл 15, 2024
4
0
1
 

Форум IT Специалистов