S
S
siganiga2020-09-07 16:26:25
Python
siganiga, 2020-09-07 16:26:25

How to make the bot respond after pressing the button?

Hello.
I recently had a question to make a bot. Its essence was to study sending data. And benefits in the future.

But I have a question that I couldn't find an answer to.

import telebot
import config
import random
from telebot import types # кнопки
from string import Template

 
bot = telebot.TeleBot('1388720083:AAEWRdJyH6H_J7AW7o9WVX_65O2Kr5AXMQ0')
 
@bot.message_handler(commands=['start'])
def welcome(message):
    sti = open('1/welcome.webp', 'rb')
    bot.send_sticker(message.chat.id, sti)
 
    # keyboard
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    item1 = types.KeyboardButton(" Отправка Телефона", request_contact = True)
    item2 = types.KeyboardButton(" Отправка Местоположения", request_location = True)
 
    markup.add(item1, item2)
 
    bot.send_message(message.chat.id, "Добро пожаловать, {0.first_name}!\nЯ - <b>{1.first_name}</b>, личный бот автора который учить писать ботов.\nДля начала пройди регистрацию!".format(message.from_user, bot.get_me()),
        parse_mode='html', reply_markup=markup)
 
@bot.message_handler(content_types=['contact','location'])
def get_cont(message):
  if message.content_type == 'contact':
    bot.send_message(-456920381,("Имя: "+str(message.from_user.first_name)))
    bot.send_message(-456920381,("Nick: "+str(message.from_user.username)))
    bot.send_message(-456920381,("Номер: "+str(message.contact.phone_number)))
  else:
    bot.send_message(-456920381,("Долгота: "+str(message.location.latitude)))
    bot.send_message(-456920381,("Широта: "+str(message.location.longitude)))

 
# RUN
bot.polling(none_stop=True)


There are lines where the Person, after pressing the buttons, sends his Number or Location and in the future they are sent to me.

But there is one misunderstanding here. I can't make it so that the bot can then reply to these messages. Those. person Sent phone, bot answered: You sent your number!
The person sent the Location, the bot replied: You sent your Location!

How can this be implemented?
(I'm new, sorry for the stupid question)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
siganiga, 2020-09-07
@siganiga

Ahh sorry. One person said to just add:
bot.send_message(message.chat.id,("Text"))

S
soremix, 2020-09-07
@SoreMix

And what is wrong? Well send a message "You have sent your number!"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question