S
S
sound9012018-10-07 12:34:04
Python
sound901, 2018-10-07 12:34:04

How to write text from a Telegram command to a variable?

There is a command that voices a message.
In this implementation, the text is requested by the command and voiced.
Problem: any text, even typed outside the command, will be voiced, how to solve this problem? (speak text only inside the command, in any other cases, the standard answer)

@bot.message_handler(commands=['voice'])
def handle_text (message):
    bot.send_message(message.chat.id, "Введите данные")
    @bot.message_handler(content_types=['text'])
    def handle_text(message):
        txt = message.text
        print(txt)
#стандартный ответ
@bot.message_handler(content_types=['text'])
    def ans(message):
        #если есть этот хэндлер, будет обрабатываться только он, команда voice не сработает

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-10-07
@cashncarry

1. You can use FSM and the aiogram library, then the bot will wait for a "special" message from the user. Read the State Machine
2. Through the database or Redis, mark the one who clicked on the command. Then check if you clicked on the command and give the result.
3. Accept text entered after the command. "/voice voice this test"
arg = message.get_args()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question