Vladislav
Vladislav

Reputation: 11

Handler doesn't work, although there are no errors in the code. (telebot)

I am new to developing bots on telebot and here is my misunderstanding. Handler 2 simply doesn't work. In the error code, pycharm does not issue, but the handler responsible for the WHOIS - DOMAIN button simply does not work. Tell me what to do.

Code:

from telebot import types
import requests
import json

token = '6230500274:AAEwvnh0WPFkjUbOp0K2iW5DiFyiKfQND9w'

bot = telebot.TeleBot(token)

@bot.message_handler(commands=['start'])
def start(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    domain = types.InlineKeyboardButton('WHOIS - DOMAIN', callback_data='domain')
    ip = types.InlineKeyboardButton('WHOIS - IP', callback_data='ip')
    markup.row(domain, ip)
    bot.send_message(message.chat.id, 'Привет! Я бот который узнать много информации о доменах и ip', reply_markup=markup)

@bot.callback_query_handler(func=lambda callback:True)
def callback_message(callback):
   if callback.data == 'domain':
       bot.send_message(callback.message.chat.id, 'ээээ')

bot.polling(none_stop=True)

I've tried everything I think should fix the problem. I wanted the button to track text at least.

Upvotes: 1

Views: 134

Answers (1)

DanVader
DanVader

Reputation: 15

You wrote callback in your lambda instead of call:

@bot.callback_query_handler(func=lambda call:True)
def callback_message(callback):
   if callback.message:
       if callback.data == 'domain':
           bot.send_message(callback.message.chat.id, 'ээээ')

Also, callback.message.chat.id may not work.

Upvotes: 0

Related Questions