0
我試圖從python-telegram-bot==7.0.1
使用CommandHandler
,但是,它沒有做我期望的任何事情。CommandHandler不能在Telegram bot庫中工作
其實,我不能讓任何狀態:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, division, print_function
import logging
import telegram
from telegram.ext import CommandHandler, CallbackQueryHandler, MessageHandler, ConversationHandler, RegexHandler
from telegram.ext import Updater, Filters
# Set up Updater and Dispatcher
updater = Updater(TOKEN)
updater.stop()
dispatcher = updater.dispatcher
# Add logging
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.WARNING)
TIME, NOTIME = range(2)
def whiteboard(bot, update):
print(1)
bot.sendMessage(text="Send update", chat_id=update.message.chat.id)
bot.sendMessage(text=update.message.text, chat_id=update.message.chat.id)
print(type(TIME))
return TIME
def whiteboard_update(bot, update):
print(2)
bot.sendMessage(text=update.message.text, chat_id=update.message.chat.id)
return TIME
def cancel(bot, update):
print(3)
bot.sendMessage(text=update.message.text, chat_id=update.message.chat.id)
bot.sendMessage(text="Это не время, а что то еще...", chat_id=update.message.chat.id)
return NOTIME
def error(bot, update, error):
logging.critical('Update "%s" caused error "%s"' % (update, error))
def main():
whiteboard_handler = CommandHandler("whiteboard", whiteboard)
dispatcher.add_handler(whiteboard_handler)
conv_handler = ConversationHandler(
entry_points=[CommandHandler("whiteboard", whiteboard)],
states={
TIME: [RegexHandler('^[0-9]+:[0-5][0-9]$', whiteboard_update), CommandHandler('cancel', cancel)],
NOTIME: [MessageHandler(Filters.text, cancel), CommandHandler('cancel', cancel)]
},
fallbacks=[CommandHandler('cancel', cancel)],
)
dispatcher.add_handler(conv_handler)
# log all errors
updater.dispatcher.add_error_handler(error)
# Poll user actions
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
所以,/whiteboard
返回它有什麼,但任何文字和/或時間(例如1:11)沒有得到我所需要的功能。
謝謝!團隊訂購幫助! –