M
M
Meezmo2021-08-25 22:09:04
Python
Meezmo, 2021-08-25 22:09:04

How to make telegram bot not send previous message with buttons?

I am making a bot that will control the computer via telegram. The bot is working, but there is a problem. Here is a screenshot:
61269496781ee506777843.png
How to make it so that before the message "How many times?" the bot didn't send the previous message and buttons? Here is the code:

@bot.message_handler(content_types=['text'])
def lmdbot(message):
    markup = telebot.types.ReplyKeyboardMarkup(row_width=2)
    markup.add(telebot.types.KeyboardButton("Рухати мишкою"))
    bot.send_message(message.from_user.id, "Що робити?", reply_markup=markup)
    if message.text == 'Рухати мишкою':
        bot.register_next_step_handler(bot.send_message(message.from_user.id, 'Скільки разів?'), mousemove)

def mousemove(message):
    times = int(message.text)
    try:
        for a in range(times):
            rh=random.randint(0, 1080)
            rw=random.randint(0, 1920)
            mouse.move(rw, rh, duration=1)
    except:
        lmdbot(message)

Sorry if I didn't explain clearly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Resolut, 2021-08-25
@Meezmo

Of course, you can make better logic, but here:

@bot.message_handler(content_types=['text'])
def lmdbot(message):
    if message.text == 'Рухати мишкою':
        bot.register_next_step_handler(bot.send_message(message.from_user.id, 'Скільки разів?'), mousemove)
    else:
        markup = telebot.types.ReplyKeyboardMarkup(row_width=2)
        markup.add(telebot.types.KeyboardButton("Рухати мишкою"))
        bot.send_message(message.from_user.id, "Що робити?", reply_markup=markup)

def mousemove(message):
    times = int(message.text)
    try:
        for a in range(times):
            rh=random.randint(0, 1080)
            rw=random.randint(0, 1920)
            mouse.move(rw, rh, duration=1)
    except:
        lmdbot(message)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question