Reputation: 1
I tried to make a bot that downloads files from Telegram channel, but except of good code I don't get files that may be downloaded in my directory. I tried this code:
@bot.message_handler(content_types=['document'])
def main(message):
if message.document.file_name.startswith("schedule"):
print(f"{Fore.GREEN}got this file: {message.document.file_name}")
id = message.document.file_id
info = bot.get_file(id)
downloaded_file = bot.download_file(file_info.file_path)
path = os.path.join(directory, message.document.file_name)
with open(path, 'wb') as channel_file:
channel_file.write(downloaded_file.content)
Is there any mistake that I've made?
Upvotes: 0
Views: 51