如何让电报机器人回复照片?

问题描述 投票:0回答:2

我有这个电报机器人,我希望它用特定照片回复特定消息,就像这样

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

def text(update, context):
    text_received = update.message.text
    if text_received == "12345":
        update.message.reply_photo(open('df.png', 'r'))
    else:
        update.message.reply_text(f'Did you say "{text_received}"?')
def main():
    TOKEN = "TOKEN"

    updater = Updater(TOKEN, use_context=True)
    dispatcher = updater.dispatcher

    dispatcher.add_handler(CommandHandler("start", start))
    dispatcher.add_handler(CommandHandler("help", help))

    dispatcher.add_handler(MessageHandler(Filters.text, text))

    dispatcher.add_error_handler(error)

    updater.start_polling()

    updater.idle()

if __name__ == '__main__':
    main()

但是我收到了这个错误

Photo_invalid_dimensions

我怎样才能让它发挥作用?

python telegram-bot python-telegram-bot
2个回答
2
投票

根据

sendPhoto
文档这里

  • 照片大小不得超过 10 MB。
  • 照片的宽度和高度合计不得超过10000。
  • 宽高比不得超过 20。

根据您收到的错误,您的照片的宽度/高度不符合第二条规则。您可以使用

sendDocument
方法,即
reply_document
代替
reply_photo


0
投票

一个公司的功能由 Q=2L1/2 给定。该公司以 100 美元的市场价格出售产品,并以 20 美元的工资雇用工人。公司应该雇用多少工人才能最大化其利润

© www.soinside.com 2019 - 2024. All rights reserved.