L
L
legolas_san2019-03-21 10:02:59
Python
legolas_san, 2019-03-21 10:02:59

How to accept only one message from a user in a telegram bot?

It is necessary after the int_on command that the bot processed only one message

User [03/21/19 09:37]
/int_on
BOT [03/21/19 09:37]
To enable the Internet on the workstation, enter the ip-address in the format of note 10.98.10.36
For example
BOT
The command is completed, click.

No other message was sent to the bot until the int_on command was run
import telebot
from telebot import types


@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
    msg = bot.send_message(message.chat.id, 'Привет! Я Красная королева!')

@bot.message_handler(commands=['stop'])
def handle_text_1 (message):
    msg = bot.send_message(message.chat.id, 'Our buisness is life itself')

@bot.message_handler(commands=['int_on'])
def handle_text (message):
    bot.send_message(message.chat.id, "Чтобы включить интернет на АРМ введите ip-адрес в формате прим.")

@bot.message_handler(content_types=['text'])
def handle_text(message):
 ip_addr = message.text
 print(ip_addr)
 bot.send_message(message.chat.id, "Выполнение команды завершено")

bot.polling()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SHADRIN, 2019-03-22
@legolas_san

sent = bot.send_message(message.chat.id, 'Чтобы включить интернет на АРМ введите ip-адрес в формате прим.')
bot.register_next_step_handler(sent, test)

def test(message):
     ip_addr = message.text
     print(ip_addr)
     bot.send_message(message.chat.id, "Выполнение команды завершено")

That's all, after a person sends a message, another function is launched and there you already start your processes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question