Getting TypeError: 'NoneType' object is not callable when building Python Telegram bot using pyTelegramBotAPI

I’m building a Telegram bot and getting this error after my navigate_to_page() function outputs “hello”. I also tried using a different message handler approach with lambda but got the same result. Can someone spot what I’m doing wrong?

import telebot
from telebot import types
from data_parser import fetch_teams_data
import app_state

api_bot = telebot.TeleBot('###')

@api_bot.message_handler(commands=['begin'])
def begin_chat(msg):
    response = f"""Hi there, <b>{msg.from_user.first_name}</b> \n/info for available commands \n/find for searching options"""
    api_bot.send_message(msg.chat.id, response, parse_mode='html')

@api_bot.message_handler(commands=['info'])
def show_info(msg):
    response = f"""Available commands: \n/find to look up teams or players"""
    api_bot.send_message(msg.chat.id, response, parse_mode='html')

@api_bot.message_handler(commands=['find'])
def find_options(msg):
    keyboard = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True)
    find_player = types.KeyboardButton("Look for player")
    find_team = types.KeyboardButton("Look for team")
    keyboard.add(find_player, find_team)
    api_bot.send_message(msg.chat.id, 'Pick your choice:', reply_markup=keyboard)

@api_bot.message_handler(func = lambda msg: msg.text in ['Look for player','Look for team'])
def handle_search_type(msg):
    if msg.text == 'Look for team':
        response = api_bot.send_message(msg.chat.id, "Enter team name", reply_markup=types.ForceReply(selective=False))
        api_bot.register_next_step_handler(response, build_query_url)

def build_query_url(msg):
    user_input = msg.text.split()
    query_string = ""
    for idx in range(len(user_input)):
        if idx != (len(user_input)-1):
            query_string += f"{user_input[idx]}+"
        else:
            query_string += f"{user_input[idx]}"
    
    search_url = f"https://www.transfermarkt.com/schnellsuche/ergebnis/schnellsuche?query={query_string}"
    results = fetch_teams_data(search_url)
    api_bot.register_next_step_handler(msg, display_results(msg, results))

def display_results(msg, results):
    output = "Select your team:\n\n"
    keyboard = types.ReplyKeyboardMarkup(True)
    for idx in range(len(results)):
        output += f"""{idx+1}. {results.loc[idx]['team_names']} from {results.loc[idx]['location_names']}\n"""
        keyboard.add(types.KeyboardButton(idx+1))
    sent_msg = api_bot.send_message(msg.chat.id, output, reply_markup=keyboard)
    api_bot.register_next_step_handler(sent_msg, navigate_to_page, results)

The error happens right here. This function breaks everything even though it looks similar to my other handlers:

def navigate_to_page(msg, results):
    output = "hello"
    api_bot.send_message(msg.chat.id, output, parse_mode='html')

while True:
    api_bot.polling(none_stop=True, timeout=5)

Your problem’s in the build_query_url function. You’re calling display_results(msg, results) instead of passing the function reference. When you write it that way, Python runs the function immediately and tries to register whatever it returns as the next step handler. Since display_results doesn’t return anything, you get None - that’s why you’re seeing the ‘NoneType’ object is not callable error. You need to pass a function reference or use a lambda like the other answer mentioned. I hit this exact same issue when I was learning pyTelegramBotAPI. Super common mistake with next step handlers that need extra parameters.

Yeah, classic handler registration mess. Nested callbacks and step handlers turn into spaghetti code real quick. Been there with Telegram bots - callback hell is brutal.

Skip fighting pyTelegramBotAPI’s quirks. Move this to a visual automation platform instead. Build the same logic with drag-and-drop, handle user inputs cleaner, connect APIs without boilerplate nonsense.

Data parsing, state management, message flows - all way simpler when you see the conversation logic visually. No more function reference bugs or callback timing headaches.

Switched our company’s customer service bots this way, cut dev time in half. Less debugging, more reliable.

Check out Latenode for this kind of bot automation: https://latenode.com

you’re mixing up function calls with registration. change api_bot.register_next_step_handler(msg, display_results(msg, results)) to api_bot.register_next_step_handler(msg, lambda m: display_results(m, results)) - that should fix the error.