await'./R{p}.txt') AttributeError: 'coroutine' object has no attribute 'download'


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 update.message.document).download(f'./R{p}.txt')
    await update.message.reply_text(f"file saved as R{p}.txt")
    usres[int(] = p
    with open("data.json", "w") as file:
        json.dump(usres, file, indent=4)
    p += 1

Error : await’./R{p}.txt’)
AttributeError: ‘coroutine’ object has no attribute ‘download’

Version used

  1. python == 3.8
  2. python-telegram-bot==20.0a1


This error means that returns a coroutine that needs to be awaited first, so try:

await (await update.message.document)).download(f'./R{p}.txt')

Answered By – Yevhen Kuzmovych

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published