在我的seesion开始轮询并通过电报发送消息后,CallbackContext错误将持续显示在cmd上

2024-05-20 08:35:51 发布

您现在位置:Python中文网/ 问答频道 /正文

import logging
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters

logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', 
    level=logging.INFO)
logger = logging.getLogger(__name__)

TOKEN = "xxxxxxxxxxxxxxxxxx"



def start(bot, update):
    print(update)
    author = update.message.from_user.first_name
    reply = "Hi! {}".format(author)
    bot.send_message(chat_id=update.message.chat_id, text=reply)

def _help(bot, update):
    help_txt = "Hey! This is a help text."
    bot.send_message(chat_id = update.message.chat_id, text=help_txt)

def echo_text(bot, update ):
    reply=update.message.text
    bot.send_message(chat_id=update.message.chat_id, text=reply)

def echo_sticker(bot, update ):
    bot.send_sticker(chat_id=update.message.chat_id, sticker=update.message.sticker.file_id)


def error(bot, update):
    logger.error("Update '%s' caused error '%s'", update, update.error) 

def main():
    updater=Updater(TOKEN, use_context=True)

    dp=updater.dispatcher

    dp.add_handler(CommandHandler("start",start))
    dp.add_handler(CommandHandler("help", _help))
    dp.add_handler(MessageHandler(Filters.text, echo_text))
    dp.add_handler(MessageHandler(Filters.sticker, echo_sticker))
    dp.add_error_handler(error)


    updater.start_polling()
    logger.info("STARTED POLLING...")
    updater.idle()
if __name__ == '__main__':
    main()

显示的错误是: 2020-06-30 09:20:00924-main-错误-更新'<;位于0x00000188F64EC0C8的Telegrame.ext.callbackcontext.callbackcontext对象>;'导致错误“CallbackContext”对象没有属性“message”


Tags: textnameaddidmessageloggingdefbot