簡體   English   中英

如何在 python-telegram-bot 中獲取語音文件

[英]How to get voice file in python-telegram-bot

我正在使用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))

為了解決這個問題,您需要等待 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))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM