【问题标题】:Send document to telegram bot using python-telegram-bot Package使用 python-telegram-bot 包将文档发送到电报机器人
【发布时间】:2021-07-16 18:06:51
【问题描述】:

我正在尝试使用带有 python-telegram-bot 包的 python 构建一个电报机器人,现在我尝试向用户发送文档

我的代码喜欢

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'的错误

那么如何以任何方式向用户发送文档文件?

【问题讨论】:

    标签: python telegram-bot python-telegram-bot


    【解决方案1】:

    telegram.Message

    消息对象没有下载属性,但是bot对象有send_document属性所以可以成功发送文档。

    doc_file = open('cv.pdf', 'rb')
    chat_id=update.effective_chat.id
    return context.bot.send_document(chat_id, doc_file)
    

    【讨论】:

    • 显示此错误 return context.bot.send_document(chat_id=update.effective_chat.id, doc_file) ^ SyntaxError: positional argument follow于keyword argument
    • 试试这个方法 chat_id=update.effective_chat.id return context.bot.send_document(chat_id, doc_file) ,它的工作
    • 好吧,这很有趣,如果它解决了你的问号,我已经更新了答案。
    猜你喜欢
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    • 2021-06-11
    相关资源
    最近更新 更多