包中有一个函数Telebot- send_message,它向用户发送消息,如果它被包含在一个变量中,假设它是x,它会在自己存储信息:
{'content_type': 'text', 'message_id': 398, 'from_user': {'id': 742445869, 'is_bot': True, 'first_name': 'Название бота', 'username': 'Bot', 'last_name': None, 'language_code': None}, 'date': 1570243933, 'chat': {'type': 'private', 'last_name': None, 'first_name': 'NickUser', 'username': 'nikUser', 'id': 936271645, 'title': None, 'all_members_are_administrators': None, 'photo': None, 'description': None, 'invite_link': None, 'pinned_message': None, 'sticker_set_name': None, 'can_set_sticker_set': None}, 'forward_from_chat': None, 'forward_from': None, 'forward_date': None, 'reply_to_message': None, 'edit_date': None, 'media_group_id': None, 'author_signature': None, 'text': 'Текст', 'entities': None, 'caption_entities': None, 'audio': None, 'document': None, 'photo': None, 'sticker': None, 'video': None, 'video_note': None, 'voice': None, 'caption': None, 'contact': None, 'location': None, 'venue': None, 'new_chat_member': None, 'new_chat_members': None, 'left_chat_member': None, 'new_chat_title': None, 'new_chat_photo': None, 'delete_chat_photo': None, 'group_chat_created': None, 'supergroup_chat_created': None, 'channel_chat_created': None, 'migrate_to_chat_id': None, 'migrate_from_chat_id': None, 'pinned_message': None, 'invoice': None, 'successful_payment': None, 'connected_website': None, 'json': {'message_id': 398, 'from': {'id': 742445869, 'is_bot': True, 'first_name': 'Название бота', 'username': 'MissionX_bot'}, 'chat': {'id': 936271645, 'first_name': 'userName', 'username': 'idUser', 'type': 'private'}, 'date': 1570243933, 'text': 'Текст'}}
如何从x带有数字的变量中请求信息0或content_type
如有必要,请保留代码以供验证:
import telebot
bot = telebot.TeleBot("Ваш токен, который получите у @BotFather")
# Бот будет реагировать только на команду /start
@bot.message_handler(commands=["start"])
def send_message(message):
if message.text.lower() == "/start":
x = bot.send_message(message.chat.id,
"Привет")
print(x)
bot.polling()
因为 send_message 是字典和 bot 对象的属性,所以将其称为字典对象就足够了:
你在问题、函数、变量中有很多东西混淆了。
试试这样: