简体   繁体   中英

How to get voice file in python-telegram-bot

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))

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM