Answer the question
In order to leave comments, you need to log in
How to get rid of duplicate messages from a tg bot?
Good evening!
Faced with the problem of duplicate messages. Does anyone know how to make the bot, after entering the city, not display the previous message, but immediately go to the function?
The screenshot is not attached, unfortunately. It looks like this:
after the start, the bot welcomes, then the get_capital function is launched:
Bot: Enter the capital:
User: Prague
Bot: Enter the capital: (how to get rid of this input)
Bot: *The get_weather function is already working here*
@bot.message_handler(content_types=['text'])
def get_capital(message):
global capital
bot.send_message(message.chat.id, text=(em.emojize(':globe_with_meridians: Введите столицу:')))
capital = message.text.lower()
if capital in config.capitals:
global page_soup
page_url = 'https://sinoptik.ua/погода-{0}'.format(capital)
page_soup = p.get_page_soup(page_url)
bot.register_next_step_handler(message, get_weather(message))
Answer the question
In order to leave comments, you need to log in
You do not bind the handler anywhere and generally work incorrectly with register_next_step_handler
https://github.com/eternnoir/pyTelegramBotAPI/blob...
@bot.message_handler(content_types=['text'])
def get_capital(message):
global capital
capital_msg = bot.send_message(message.chat.id, text=(em.emojize(':globe_with_meridians: Введите столицу:')))
capital = message.text.lower()
if capital in config.capitals:
global page_soup
page_url = 'https://sinoptik.ua/погода-{0}'.format(capital)
page_soup = p.get_page_soup(page_url)
bot.register_next_step_handler(capital_msg, get_weather)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question