我對編碼和 python 比較陌生。我正在嘗試使用遠程機器人制作一個電報機器人。我有一個必須去的流程。例如:/start 之后,我應該收到一條短信。因此,我創建了一個 running_work_list,其中按順序排列我的工作流程,完成后,我刪除索引 0 元素。'start' 是數組中的第一個元素。所以我嘗試實現這樣的東西,這樣我就可以輕松地編寫每個步驟,而不是查看輸入并做出決定。但是,盡管放入了 if 語句,即使條件失敗,“@bot.message_handler()”也會運行。 if running_work_list[0]=='start': print('inside if') @bot.message_handler(commands=['start','new test']) def start(message): print('user sent start') bot.send_message(message.chat.id,welcome_message) running_work_list.pop(0) print(f'work flow deciding list {running_work_list}') @bot.message_handler(content_types=['text','photo','poll']) def bot_intro(message): print('here') print(f'user sent {message.text}') bot.send_message(message.chat.id,BOT_INTRO_MSG)以下是我得到的輸出。用戶首先發送了 /start,然后發送了一些其他隨機文本。 inside if user sent start work flow deciding list ['test_name', 'test_description', 'test_time', 'test_image', 'test_poll'] here user sent fdf即使我們將“@bot.message_handler()”放在 if 語句中,它也會運行嗎?
在 telebot @bot.message_handler() 中運行,即使它保存在 if 語句中
慕田峪9158850
2023-08-08 10:27:28