Replies: 3 comments
-
No issue in the telebot library.
Never heard about "on()" method in pyTelegramBotAPI library. |
Beta Was this translation helpful? Give feedback.
-
mmmh recive: File "/root/echo_bot.py", line 9, in the code is: import telebot bot = telebot.TeleBot("") def handle_message(message): bot.add_handler(handle_message, telebot.events.Message()) |
Beta Was this translation helpful? Give feedback.
-
Hello all
I am experiencing an error in the on() method of the telebot library. The code I am using is as follows:
import telebot
bot = telebot.TeleBot("TOKEN")
@bot.on(telebot.events.Message)
def handle_message(message):
if message.from_user.id == 111111111111:
bot.send_message(-1111111111111, message.text)
bot.polling()
When I run this code, I receive the following error:
Traceback (most recent call last):
File "/root/echo_bot.py", line 5, in
@bot.on(telebot.events.Message)
AttributeError: 'TeleBot' object has no attribute 'on'
According to the documentation of the telebot library, the on() method was removed starting from version 13.0. To register a handler for an event, you need to use the add_handler() method.
The updated code is as follows:
import telebot
bot = telebot.TeleBot("TOKEN")
def handle_message(message):
if message.from_user.id == 1111111111:
bot.send_message(-1111111111, message.text)
bot.add_handler(handle_message, telebot.events.Message())
bot.polling()
This code works correctly with version 13.0 or later of the telebot library.
I would like to ask if it is possible to fix this issue in the telebot library.
Thank you for your cooperation.
Sincerely,
Beta Was this translation helpful? Give feedback.
All reactions