如何使用 pyTelegramBotAPI 将文档发送到 Telegram Bot
How to send a document to a Telegram Bot using pyTelegramBotAPI
我正在尝试使用 pyTelegramBotAPI 包开发 Telegram 机器人,我需要在用户输入特定 / 命令时输出多个文档。我试过下面的代码,但它显示错误。
def pca_papers(self, message):
bot.send_message(message.chat.id, "Files incoming")
file = open('https://atikegalle.com/uploads/1514125303.pdf', 'rb')
bot.send_document(message.chat.id, file)
错误:
File "C:\Users\pasin\Documents\tgbot\pastpapers.py", line 26, in pca_papers
file = open('https://atikegalle.com/uploads/1514125303.pdf', 'rb')
OSError: [Errno 22] Invalid argument: 'https://atikegalle.com/uploads/1514125303.pdf'
open
built-in function is for working with local files, not files accessible via HTTP. According to send_document
docs 第二个参数可能是
an HTTP URL as a String for Telegram to get a file from the Internet
所以下面应该有效
def pca_papers(self, message):
bot.send_message(message.chat.id, "Files incoming")
bot.send_document(message.chat.id, 'https://atikegalle.com/uploads/1514125303.pdf')
我没有能力测试,如果有效请尝试写。
我正在尝试使用 pyTelegramBotAPI 包开发 Telegram 机器人,我需要在用户输入特定 / 命令时输出多个文档。我试过下面的代码,但它显示错误。
def pca_papers(self, message):
bot.send_message(message.chat.id, "Files incoming")
file = open('https://atikegalle.com/uploads/1514125303.pdf', 'rb')
bot.send_document(message.chat.id, file)
错误:
File "C:\Users\pasin\Documents\tgbot\pastpapers.py", line 26, in pca_papers
file = open('https://atikegalle.com/uploads/1514125303.pdf', 'rb')
OSError: [Errno 22] Invalid argument: 'https://atikegalle.com/uploads/1514125303.pdf'
open
built-in function is for working with local files, not files accessible via HTTP. According to send_document
docs 第二个参数可能是
an HTTP URL as a String for Telegram to get a file from the Internet
所以下面应该有效
def pca_papers(self, message):
bot.send_message(message.chat.id, "Files incoming")
bot.send_document(message.chat.id, 'https://atikegalle.com/uploads/1514125303.pdf')
我没有能力测试,如果有效请尝试写。