[英]How to make telegram bot reply with a photo?
我有這個電報機器人,我希望它回復帶有特定照片的特定消息,就像這樣
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
我怎樣才能讓它工作?
根據此處的sendPhoto
文檔:
根據您收到的錯誤,您的照片的寬度/高度不符合第二條規則。 您可以使用sendDocument
方法,它是reply_document
而不是reply_photo
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.