@tofel

Не работает телеграм бот на python?

Начал изучать боты для телеграмма на python
Вот код бота
import telebot
from telebot import apihelper # Нужно для работы Proxy
import config # Импорт config.py
import urllib.request # request нужен для загрузки файлов от пользователя

bot = telebot.TeleBot(config.token) # Передаём токен из файла config.py
apihelper.proxy = {'https':config.proxy} # Передаём Proxy из файла config.py




# Тут работаем с командой start
@bot.message_handler(commands=['start'])
def welcome_start(message):
    bot.send_message(message.chat.id, 'Приветствую тебя user')

# Тут работаем с командой help
@bot.message_handler(commands=['help'])
def welcome_help(message):
    bot.send_message(message.chat.id, 'Чем я могу тебе помочь')

@bot.message_handler(content_types=["text"])
def text(message):
    if message.text == 'hello':
        bot.send_message(message.chat.id, 'И тебе hello')

@bot.message_handler(content_types=["text"])
def text(message):
    if message.text == 'photo':
        file = open('"C:/photo.png"', 'rb')
        bot.send_photo(message.chat.id, file)

@bot.message_handler(content_types=["audio"])
def handle_docs_document(message):
    audio_id = message.audio.file_id
    file_info = bot.get_file(audio_id)
    urllib.request.urlretrieve(f'https://api.telegram.org/file/bot{config.token}/{file_info.file_path}', file_info.file_path)

@bot.message_handler(content_types=["document"])
def handle_docs_audio(message):
    document_id = message.document.file_id
    file_info = bot.get_file(document_id)
    urllib.request.urlretrieve(f'https://api.telegram.org/file/bot{config.token}/{file_info.file_path}', file_info.file_path)
bot.polling() # запускаем бота


Отправка команд , или текста бот отрабатывает отлично. Но как только я пытаюсь отправить файл боту или от бота юзеру. Ничего не происходит. Не могу понять в чем причина?!
  • Вопрос задан
  • 1055 просмотров
Решения вопроса 1
deepblack
@deepblack Куратор тега Python
@bot.message_handler(content_types=["text"])
def text(message):
    if message.text == 'hello':
        bot.send_message(message.chat.id, 'И тебе hello')
    if message.text == 'photo':
        file = open('"C:/photo.png"', 'rb')
        bot.send_photo(message.chat.id, file)
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы