Answer the question
In order to leave comments, you need to log in
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:
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)
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question