How to get voice file in python-telegram-bot

Question:

Im using python-telegram-bot

im trying to get voice file from user in chat, but im getting error

error:

RuntimeWarning: coroutine 'ExtBot.get_file' was never awaited
return await self.callback(update, context)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

and this is my codes:

async def get_voice(update: Update, context: CallbackContext):
    # get basic info about the voice note file and prepare it for downloading
    new_file = context.bot.get_file(update.message.voice.file_id)
    print('new_file')


    app = ApplicationBuilder().token(TOKEN).build()
    app.add_handler(MessageHandler(filters.VOICE, get_voice))
Asked By: Mahdi mk

||

Answers:

In order to fix this you need to await context.bot.get_file

async def get_voice(update: Update, context: CallbackContext):
# get basic info about the voice note file and prepare it for downloading
new_file =await context.bot.get_file(update.message.voice.file_id)
print('new_file')


app = ApplicationBuilder().token(TOKEN).build()
app.add_handler(MessageHandler(filters.VOICE, get_voice))
Answered By: testINGHUb