使用 python-telegram-bot 包将文档发送到电报机器人
Send document to telegram bot using python-telegram-bot Package
我正在尝试使用 python 和 python-telegram-bot 包构建一个电报机器人,它使用文本命令现在我尝试向用户发送文档
我的代码像
def start(update, context):
return update.message.download(open('cv.pdf', 'rb'))
但它显示了类似 return update.message.download(open('cv.pdf', 'rb')) AttributeError: 'Message' object has no attribute 'download'
的错误
那怎么给用户发送文档文件呢?
消息对象没有下载属性,但是bot对象有send_document属性,所以可以成功发送文档。
doc_file = open('cv.pdf', 'rb')
chat_id=update.effective_chat.id
return context.bot.send_document(chat_id, doc_file)
我正在尝试使用 python 和 python-telegram-bot 包构建一个电报机器人,它使用文本命令现在我尝试向用户发送文档
我的代码像
def start(update, context):
return update.message.download(open('cv.pdf', 'rb'))
但它显示了类似 return update.message.download(open('cv.pdf', 'rb')) AttributeError: 'Message' object has no attribute 'download'
那怎么给用户发送文档文件呢?
消息对象没有下载属性,但是bot对象有send_document属性,所以可以成功发送文档。
doc_file = open('cv.pdf', 'rb')
chat_id=update.effective_chat.id
return context.bot.send_document(chat_id, doc_file)