I want to save a file in txt format in my system, but I get an error
async def Getfile(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
global p, usres
await context.bot.get_file(await update.message.document).download(f'./R{p}.txt')
await update.message.reply_text(f"file saved as R{p}.txt")
usres[int(update.message.from_user.id)] = p
with open("data.json", "w") as file:
json.dump(usres, file, indent=4)
p = 1
print("ok")
Error : await context.bot.get_file(update.message.document).download(f'./R{p}.txt') AttributeError: 'coroutine' object has no attribute 'download'
Version used
- python == 3.8
- python-telegram-bot==20.0a1
CodePudding user response:
This error means that context.bot.get_file(update.message.document)
returns a coroutine that needs to be awaited first, so try:
await (await context.bot.get_file(await update.message.document)).download(f'./R{p}.txt')