I'm making a bot that sends messages to users 2 times a day on topic they choose. But I also want users to have an opportunity to change the topic. That's why I need to make one message handler (that sends messages to users) stop if user pushes the button to change topic. Now if user changes the topic, bot continues sending messages on both topics. Do you know any solutions?
That's my code:
@dp.message_handler(lambda message: message.text == 'Change topic')
async def send_welcome(message: types.Message):
bot.clear_step_handler_by_chat_id(call.message.chat.id)
await message.reply("Hello! Choose the topic",reply_markup=keyboard_choice)
@dp.message_handler()
async def echo(message: types.Message):
if message.text in data.keys():
keyboard_change = types.ReplyKeyboardMarkup(resize_keyboard=True).\
add(types.KeyboardButton(text='Change topic'))`
await message.reply( 'You can change the topic', reply_markup=keyboard_change)
topic=message.text
while True:
await asyncio.sleep(1)
now=datetime.now()
current_time=now.strftime('%H:%M:%S')
if (current_time =='14:24:30') or (current_time =='14:24:00'):
await message.reply(random.choice(data[topic]))
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)