如何解决AttributeError:“ CallbackContext”“更新”对象没有属性“消息”
将我的tg-bot转移到新服务器后,我遇到了问题。绝对不知道为什么我有错误。似乎我丢失了一些要安装的python数据包。在操作系统参数相同的旧服务器中,该机器人没有任何问题。
对不起,如果我的错误很幼稚。我尝试用谷歌搜索我的错误,但是没有答案。
代码1:
def start(bot,update):
if update.message.from_user.username == AAA:
bot.sendMessage(chat_id=update.message.chat_id,text="Text_one")
else:
bot.sendMessage(chat_id=update.message.chat_id,text="Text_two")
...
updater = Updater(token=bot_token)
start_handler = CommandHandler('start',start)
updater.dispatcher.add_handler(start_handler)
错误1:
File "/usr/local/lib/python3.7/site-packages/telegram/ext/dispatcher.py",line 425,in process_update handler.handle_update(update,self,check,context)
File "/usr/local/lib/python3.7/site-packages/telegram/ext/handler.py",line 145,in handle_update return self.callback(update,context)
File "./bot.py",line 43,in start
if update.message.from_user.username == AAA:
AttributeError: 'CallbackContext' object has no attribute 'message'
代码2:
def rating(bot,update):
bot.send_sticker(chat_id,'some_sticker_id')
...
rating_handler = CommandHandler('rating',rating)
updater.dispatcher.add_handler(rating_handler)
错误2:
File "/usr/local/lib/python3.7/site-packages/telegram/ext/dispatcher.py",line 108,in rating
bot.send_sticker(chat_id,'some_sticker_id')
AttributeError: 'Update' object has no attribute 'send_sticker'
解决方法
处理程序签名不正确:
def start(update,context):
context.bot.sendMessage(chat_id=update.message.chat_id,'Text One')
updater.dispatcher.add_handler(CommandHandler('start',start))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。