F
F
From Prog2021-06-07 22:19:10
Python
From Prog, 2021-06-07 22:19:10

How to end the output of a message in a TG bot that is called by a command?

I would be very grateful for the answer to this question

Code:

@my_bot.message_handler(commands = ['rate'])
def messages(message):
  keyboard = types.InlineKeyboardMarkup(row_width = 3)
  value_bitcoin = types.InlineKeyboardButton('Bitcoin',callback_data = 'bitcoin')
  keyboard.add(value_bitcoin)
  my_bot.send_message(message.chat.id, 'Выберите, курс какой валюты вы хотите узнать', reply_markup = keyboard)

@my_bot.callback_query_handler(func = lambda call: True)
def answer(call):

  def send_currency_rates(call_data):
    if call_data == 'bitcoin':
      source = requests.get(url_bitcoin, headers = headers)
      html = BeautifulSoup(source.text, 'lxml')
      my_bot.send_message(call.message.chat.id, 'Курс Bitcoin: {0}'.format(html.find('span', {'class': 'pid-1057391-last', 'id': 'last_last'}).get_text()))
      time.sleep(2)

        if call.data == 'bitcoin':
    while True:
      send_currency_rates(call.data)

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

How can I make it so that if the user writes "stop", then the cycle of sending the exchange rate stops? I don't understand at all

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question