Answer the question
In order to leave comments, you need to log in
What's wrong with the code? Bot not working?
import telebot
import config
bot = telebot.TeleBot(config.TOKEN)
@bot.message_handler(commands=['start'])
def welcome(message):
sti = open('static/welcome.webp', 'rb')
bot .send_sticker(message.chat.id, sti)
bot.send_message(message.chat.id, "Welcome {0.first_name}!\nI'm {1.first_name} , a bot designed to be a guinea pig!". format(message.from_user, bot.get_me()),
parse_mode='html')
@bot.message_handler(content_types=['text'])
def lalala(message):
bot.send_message(message.chat.id, message. text)
#run
bot.polling(none_stop=True)
throws an error
Traceback (most recent call last):
File "C:\python\test.py", line 19, in
bot.polling(none_stop=True)
File "C:\Users\MUTESHOV\AppData\Local\Programs\Python\Python39 \lib\site-packages\telebot\__init__.py", line 514, in polling
self.__threaded_polling(none_stop, interval, timeout, long_polling_timeout)
File "C:\Users\MUTESHOV\AppData\Local\Programs\Python\Python39\ lib\site-packages\telebot\__init__.py", line 573, in __threaded_polling
raise e
File "C:\Users\MUTESHOV\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py ", line 536, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Users\MUTESHOV\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\util.py", line 117, in raise_exceptions
raise self.exception_info
File "C:\Users\MUTESHOV\ AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\util.py", line 69, in run
task(*args, **kwargs)
File "C:\python\test.py", line 8, in welcome
sti = open('static/welcome.webp', 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'static/welcome.webp'
Answer the question
In order to leave comments, you need to log in
1. Format the code as it should be, with the </> button
2. The bot directly tells you what the matter is:
FileNotFoundError: [Errno 2] No such file or directory: 'static/welcome.webp'
It needs a static subdirectory in the current working directory, and it contains the file welcome.webp
If the file exists, check if there are any typos in the name.
Also note that the path to the file is relative and therefore depends on the current working directory. Change the path to absolute, or calculate this path relative to the path to the executable file of the bot.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question