如何在 Telegram 上根据文件 ID 发送文件

How to send file according to file ID on Telegram

如何根据文件 ID 将 Telegram 上存在的文件发送(而不是转发)给用户?

我知道所有上传到 Telegram 的文件都有唯一的 ID。我如何提取该 ID 以及通过提取的 ID 发送该文件的功能或方法是什么? (我使用 Python Telepot 库)

import telepot
from telepot.loop import MessageLoop
def on_chat_message(msg):
content_type, chat_type, chat_id = telepot.glance(msg,'chat')
if content_type == 'text':
    user_msg_text = msg['text']
    if user_msg_text == '/start':
        bot.sendDocument(chat_id=chat_id, )
TOKEN = "479761462:AAE8yqX2RGCbynHJgShIdJzCZWYF9SSBUkU"
bot = telepot.Bot(TOKEN)
MessageLoop(bot, {'chat': on_chat_message,
                  'callback_query': on_callback_query}).run_as_thread()
print('Listening ...')

我应该在 sendDocument() 方法的第二个参数中输入什么?

import telepot
from telepot.loop import MessageLoop
def on_chat_message(msg):
   content_type, chat_type, chat_id = telepot.glance(msg,'chat')
     if content_type == 'document':
        file_id = msg['document']['file_id']
        print(file_id)
TOKEN = "479761462:AAE8yqX2RGCbynHJgShIdJzCZWYF9SSBUkU"
bot = telepot.Bot(TOKEN)
MessageLoop(bot, {'chat': on_chat_message,
              'callback_query': on_callback_query}).run_as_thread()
print('Listening ...')

你应该先从文档file.when中提取file_id你运行你的机器人,发送一个文档给机器人,你可以打印它并复制它,然后将它传递给这个命令: bot.sendDocument(chat_id=chat_id,file_id) 您应该放置您复制的短语而不是 file_id。