如何在Python电报机器人中获取语音文件

y0u0uwnf  于 2023-01-08  发布在  Python
关注(0)|答案(1)|浏览(156)

正在使用python-telegram-bot
我尝试从聊天中的用户获取voice file,但我获取的是error

    • 错误:**
RuntimeWarning: coroutine 'ExtBot.get_file' was never awaited
return await self.callback(update, context)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
    • 这是我的密码**
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))
nnsrf1az

nnsrf1az1#

为了解决这个问题,你需要等待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))

相关问题