Handler 不起作用,尽管代码中没有错误。 (远程机器人)

问题描述 投票:0回答:1

我是在远程机器人上开发机器人的新手,这是我的误解。处理程序 2 根本不起作用。在错误代码中,pycharm 不会发出问题,但负责 WHOIS - DOMAIN 按钮的处理程序根本不起作用。告诉我该怎么做。

代码:

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)

我已经尝试了所有我认为应该解决问题的方法。我希望按钮至少能够跟踪文本。

python telegram-bot telebot
1个回答
0
投票

您在

callback
中写了
lambda
而不是
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, 'ээээ')

此外,

callback.message.chat.id
可能不起作用。

© www.soinside.com 2019 - 2024. All rights reserved.