B
B
bakin20042019-09-29 14:58:53
Python
bakin2004, 2019-09-29 14:58:53

How can I make it so that the text is not displayed 2 times?

users = [id1]

@bot.message_handler(func=lambda message: message.chat.id not in users)
def CheckUser(message):
    bot.send_message(message.chat.id, "Привет.")

@bot.message_handler(func=lambda message: message.chat.id in users)
def CheckUser(message):
    bot.send_message(message.chat.id, "Чтобы начать работу с программой введите /command ")
    if message.text == '/command':
        bot.send_message(message.chat.id, 'Все прошло успешно')
    else:
        bot.send_message(message.chat.id, 'Извините, я не понял команду. Чтобы начать работу с программой введите /command ')

bot.polling(none_stop=True, interval=0)

So I simultaneously display the text "To start working with the program, enter / command" and 1 text from the else / if construct. How to make it so that everything is displayed separately and the meaning of the program does not change?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Neverov, 2019-09-29
@bakin2004

If you want to cram everything into one message, use variables and send everything at the very end. JS implementation:

function Checkuser(message) {
    let answer = 'Чтобы начать работу с программой введите /command';

    if (message.text === '/command') {
        answer += '\nВсе прошло успешно';
    } else{
        answer += '\nИзвините, я не понял команду. Чтобы начать работу с программой введите /command';
    }

    bot.sendMessage(chatId, answer);
    
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question