I’m trying to create a basic Telegram bot using Python. I’m using the telebot library but I’m running into an error. Here’s what I’ve got so far:
import telebot
my_bot = telebot.BotCreator("1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij")
@my_bot.message_handler(commands=['hello', 'hi'])
def greet_user(message):
my_bot.reply_to(message, "Hey there! How's it going?")
@my_bot.message_handler(func=lambda message: True)
def repeat_message(message):
my_bot.reply_to(message, message.text)
my_bot.start_polling()
When I run this code, I get an error saying the telebot module doesn’t have an attribute called ‘BotCreator’. I’m not sure what I’m doing wrong. Can anyone help me figure out why this isn’t working? I thought I followed the basic structure correctly, but maybe I’m missing something obvious. Thanks in advance for any help!
The problem in your code is that you’re using the ‘BotCreator’ class, which doesn’t exist in the telebot library. Instead, you should initialize your bot with the correct ‘TeleBot’ class. For example, replace the line:
my_bot = telebot.BotCreator(“1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij”)
with:
my_bot = telebot.TeleBot(“1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij”)
Additionally, update your message sending method by using ‘send_message’ with ‘message.chat.id’ as the first argument instead of ‘reply_to’, and change ‘start_polling()’ to ‘polling()’. These adjustments should resolve the attribute error you encountered.
yo, i think i kno whats goin on. ur using ‘BotCreator’ but thats not a thing in telebot. try using ‘TeleBot’ instead like this:
my_bot = telebot.TeleBot(‘your_token_here’)
also, use ‘send_message’ not ‘reply_to’ and ‘polling()’ at the end. that should fix it up for ya!
I’ve encountered similar issues when setting up Telegram bots with Python. The problem is actually quite simple - you’re using ‘BotCreator’ which isn’t a part of the telebot library. Instead, you should use ‘TeleBot’ to initialize your bot.
Here’s how you can fix it:
my_bot = telebot.TeleBot(‘your_bot_token_here’)
Also, make sure you’re using ‘send_message’ instead of ‘reply_to’ for sending messages. The ‘chat.id’ is needed as the first argument. Lastly, use ‘polling()’ instead of ‘start_polling()’.
With these changes, your bot should work fine. Don’t forget to keep your bot token secure and not share it publicly. If you’re still having issues, double-check your telebot library version - sometimes outdated versions can cause unexpected errors.