J
J
JiMoon2022-02-14 19:32:29
Python
JiMoon, 2022-02-14 19:32:29

TypeError: 'NoneType' object is not callable telegram bot?

Hello. I am writing my Telegram bot in python (pyTelegramBotAPI). I can't modify my bot to make it work. Please help me fix the error.
The code:

import telebot
from telebot import types

a = True
bot = telebot.TeleBot('token')
print(bot.get_me())

@bot.message_handler(commands=["start"])
def start(m):
    markup = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
    item1 = telebot.types.KeyboardButton("Я в кофейне!")
    item2 = telebot.types.KeyboardButton("Я дома...")
    markup.add(item1)
    markup.add(item2)
    bot.send_message(m.chat.id, 'Привет!\nЭто онлайн официант кофейни PRIMETIME!\nПожалуйста, выбери где ты сейчас.',  reply_markup=markup)

@bot.message_handler(content_types=["text"])
def handle_text(message):
    if message.text.strip() == 'Я в кофейне!':
        msg = bot.send_message(message.chat.id, 'Отлично! Ты сейчас в кофейне!\nЗначит тебе будет легче делать заказ!', reply_markup=types.ReplyKeyboardRemove())
        bot.register_next_step_handler(msg, handle_text_2(msg))
        print('Человек в кофейне')

    elif message.text.strip() == 'Я дома...':
        bot.send_message(message.chat.id, "bebroit")

@bot.message_handler(content_types=["text"])
def handle_text_2(message):
    if a:
        global places
        places = ["6-й микрорайон, 1 (Краснообск)", "Орджоникидзе, 30", "Кирова, 23",
                  "проспект Карла Маркса, 29", "Героев Революции, 64", "Орджоникидзе, 18",
                  "Никольский проспект, 1 (БЦ Кольцово)", "площадь Карла Маркса, 7 (Сан Сити)",
                  "Советская, 8", "Кошурникова, 33", "Большевистская, 45/1 (РЕКА)",
                  "Красный проспект, 157/1", "Красный проспект, 2/1", "Выставочная, 38/1",
                  "Военная, 5 (Аура)", "Дуси Ковальчук, 179/5 (БЦ Колибри)", "Богдана Хмельницкого, 27",
                  "Фрунзе, 242 (ДЦ Новая высота)", "Максима Горького, 53", "Дуси Ковальчук, 28д",
                  "Красный проспект, 101 (Ройял Парк)", "Светлановская, 50 (Большая Медведица)"]
        global markup
        markup = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
        for place in places:  # вот и пригодилась наша глобальная переменная (и без всяких global)
            markup.add(telebot.types.KeyboardButton(place))
        print('Кнопки добавлены!')  # если тебе вообще это нужно
        bot.send_message(message.chat.id, 'Пожалуйста, выбери кофейню, в которой ты сейчас находишься.', reply_markup=markup)
        if a:
            if message.text.strip() in places:
                bot.send_message(message.chat.id, f"Отлично! Ты сейчас по адресу: {message.text.strip()}")


bot.polling(none_stop=True)


mistake:
Traceback (most recent call last):
  File "/Users/antongorestov/Desktop/PrimetimeBot/bot.py", line 50, in <module>
    bot.polling(none_stop=True)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/telebot/__init__.py", line 658, in polling
    self.__threaded_polling(non_stop, interval, timeout, long_polling_timeout, allowed_updates)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/telebot/__init__.py", line 720, in __threaded_polling
    raise e
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/telebot/__init__.py", line 680, in __threaded_polling
    self.worker_pool.raise_exceptions()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/telebot/util.py", line 135, in raise_exceptions
    raise self.exception_info
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/telebot/util.py", line 87, in run
    task(*args, **kwargs)
TypeError: 'NoneType' object is not callable


PS Sorry for the shitty code with the variable a in the xd code, I don't know how to fill the line with something

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
PavelMos, 2022-02-14
@PavelMos

It is directly written right there - AttributeError: module 'telebot.types' has no attribute 'ReplyKeyboardRemove'
1. look in the description or through telebot.types.__dir__() what attributes and methods telebot.types has
2. there is ReplyKeyboardRemove, and this a function (method), not an attribute, that is, it must be called with brackets with some parameters or without parameters
, also in the search, see ReplyKeyboardRemove Self-fix
- I looked at the script, ReplyKeyboardRemove is called as a function, but there is no such attribute in the error. Need to figure it out.

S
soremix, 2022-02-15
@SoreMix

AT

bot.register_next_step_handler(msg, handle_text_2(msg))
mistake. The second argument must be the name of the function, but you passed the result of the execution

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question