如何解决如何让我的机器人接收并保存我发送的文件?
如何让我的机器人接收并保存我通过电报发送的文件? 我希望我的机器人接收我从手机发送的 pdf 文件。我正在用 python 做这件事,但我对此不知所措,不知道如何解决。
解决方法
我做了这个,但我没有得到结果
list="filename.pdf"
def CambiarLista(update,context):
bot = context.bot
text = update.message.text
ChatId = update.message.chat_id
update.message.reply_text('Enviame el documento!')
file_content = list._get_file()
update.message.reply_text('Este es el documento que recibi:' + file_content + 'es correcto?')
keyboard = []
keyboard.append([KeyboardButton(f'Si,remplazar y guardar',callback_data='9'),KeyboardButton(f'No,eliminar y salir',callback_data='10')])
reply_markup = ReplyKeyboardMarkup(keyboard,one_time_keyboard=True,resize_keyboard=True)
update.message.reply_text('Elige una de las siguientes opciones:',reply_markup=reply_markup)
正如您在这一行中看到的,我等待接收文件,但我认为我没有做对,因为在那行之后我没有收到以下消息
file_content = list._get_file()
,
请记住,要处理 Telegram Bot 上的文件,您必须拥有文件的 file_id
。
处理 document
:
def file_handler (update,context):
chat_id = update.message.chat_id
## bot geting the document and its file_name
doc = update.message['document']['file_id'].get_file()
fileName = update.message['document']['file_name']
##bot saving this file to a directory on your PC
doc.download(f'{path_to_your_directory}\\{fileName}')
和def main()
:
dp = updater.dispatcher
dp.add_handler(MessageHandler(Filters.document,file_handler))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。