1

(Эхо-бот из видео Хауди хо) Попытался запустить через консоль, вставив токен от BotFahter в конфиг, но бот не реагирует на /start и какие либо другие сообщения. Ошибок в консоли никаких нет и бот запущен. В чем проблема?

import telebot
import config

bot = telebot.TeleBot(config.TOKEN)

@bot.message_handler(content_type=['text'])

def ans(message):
    bot.send_message(message.chat.id, message.text)

bot.polling(none_stop=True)

1 ответ 1

1

Согласно документации в обработчике указывается content_types:

@bot.message_handler(content_types=['text'])
def ans(message):
    bot.send_message(message.chat.id, message.text)

Доступные типы:

text, audio, document, photo, sticker, video, video_note, voice, location, contact, new_chat_members, left_chat_member, new_chat_title, new_chat_photo, delete_chat_photo, group_chat_created, supergroup_chat_created, channel_chat_created, migrate_to_chat_id, migrate_from_chat_id, pinned_message

Для добавления реакций на команды используется обработчик commands:

@bot.message_handler(commands=['start'])
def send_welcome(message):
    bot.reply_to(message, "Howdy, how are you doing?")

так же в обработчике может быть указано несколько команд:

@bot.message_handler(commands=['start', 'help'])

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.