Задать вопрос

Существует ли content_types = «любой» (telebot)?

В общем, хотелось бы избежать ненужной писанины. Вы можете заметить, что я проверяю наличие нужного мне типа сообщения в огромном списке.

import telebot
from telebot import types 


bot = telebot.TeleBot("токен")

CONTENT_TYPES = ["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"]

@bot.message_handler(commands=["takenumber"])
def get_phone(message):
    keyboard = types.ReplyKeyboardMarkup(row_width=1,
                                         resize_keyboard=True)  # подключаем клавиатуру через дополнение types
    button_phone = types.KeyboardButton(text="send_phone", request_contact=True)  # указываем название кнопки
    keyboard.add(button_phone)  # добавляем кнопку
    bot.send_message(message.chat.id, "Вы можете оправить номер нажав на кнопку send_phone", reply_markup=keyboard)

    @bot.message_handler(content_types=CONTENT_TYPES)
    def confirming(message):

        if message.content_type == "contact":
            keyboard = types.ReplyKeyboardRemove()
            bot.send_message(message.chat.id, "Мы получили ваш номер.", reply_markup=keyboard)
        else:
            keyboard = types.ReplyKeyboardRemove()
            bot.send_message(message.chat.id, "Номер не был отправлен.", reply_markup=keyboard)


print("Начали")
bot.polling()  # запуск бота


P.S. Буду также благодарен, если подскажете как отредактировать текст на этом сайте, чтобы его проще было читать. (Чтобы со всеми выделениями цвета и пр.)
  • Вопрос задан
  • 16079 просмотров
Подписаться 1 Простой 1 комментарий
Пригласить эксперта
Ответы на вопрос 3
SoreMix
@SoreMix Куратор тега Python
yellow
Нет
Ответ написан
Комментировать
@OlegVladimirovich
@dp.message_handler(content_types=types.ContentType.ANY)
Это поможет.
Ответ написан
Комментировать
@GameRoMan
Вот что есть

import telebot

print(telebot.util.update_types)
# ['message', 'edited_message', 'channel_post', 'edited_channel_post', 'inline_query', 'chosen_inline_result', 'callback_query', 'shipping_query', 'pre_checkout_query', 'poll', 'poll_answer', 'my_chat_member', 'chat_member', 'chat_join_request', 'message_reaction', 'message_reaction_count', 'chat_boost', 'removed_chat_boost']

print(telebot.util.content_type_media)
# ['text', 'animation', 'audio', 'document', 'photo', 'sticker', 'story', 'video', 'video_note', 'voice', 'contact', 'dice', 'game', 'poll', 'venue', 'location', 'invoice', 'successful_payment', 'connected_website', 'passport_data', 'web_app_data']

print(telebot.util.content_type_service)
# ['new_chat_members', 'left_chat_member', 'new_chat_title', 'new_chat_photo', 'delete_chat_photo', 'group_chat_created', 'supergroup_chat_created', 'channel_chat_created', 'message_auto_delete_timer_changed', 'migrate_to_chat_id', 'migrate_from_chat_id', 'pinned_message', 'users_shared', 'chat_shared', 'write_access_allowed', 'proximity_alert_triggered', 'forum_topic_created', 'forum_topic_edited', 'forum_topic_closed', 'forum_topic_reopened', 'general_forum_topic_hidden', 'general_forum_topic_unhidden', 'giveaway_created', 'giveaway', 'giveaway_winners', 'giveaway_completed', 'video_chat_scheduled', 'video_chat_started', 'video_chat_ended', 'video_chat_participants_invited']
Ответ написан
Комментировать
Ваш ответ на вопрос

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

Похожие вопросы