So i use AI to write me a telegram bot in python, it run but no function.
I try to make a file manager that the bot can know what file i uploaded and do something similar like google drive stuff.
when i use /upload, any file that i upload should be save, but not. And now I'm stuck. Any solution are welcome.
Here's the full script
def upload(update: Update, context: CallbackContext) -> None:
if update.message.text == '/upload':
context.chat_data['uploading'] = True
update.message.reply_text('Upload mode activated. Send files to upload them. Send /uploadstop to stop uploading.')
return
if 'uploading' in context.chat_data and context.chat_data['uploading']:
try:
file = update.message.document
file_name = file.file_name
file_id = file.file_id
newFile = context.bot.get_file(file_id)
newFile.download(file_name)
if 'uploaded_files' not in context.chat_data:
context.chat_data['uploaded_files'] = []
context.chat_data['uploaded_files'].append(file_name)
update.message.reply_text(f'File {file_name} uploaded successfully!')
# Show the file status as uploading and uploaded to chat_data
if 'file_status' not in context.chat_data:
context.chat_data['file_status'] = {}
context.chat_data['file_status'][file_name] = 'Uploading'
update.message.reply_text(f'File {file_name} status: {context.chat_data["file_status"][file_name]}')
context.chat_data['file_status'][file_name] = 'Uploaded'
update.message.reply_text(f'File {file_name} status: {context.chat_data["file_status"][file_name]}')
except Exception as e:
logging.error(f'Error uploading file: {e}')
update.message.reply_text(f'Error uploading file: {e}')
I'm using python-telegram-bot 13.7, and everything run with no error. But it just can't detect any file i uploaded.
I am using python 3.11, if you want use it feel free to copy.