我正在學(xué)習(xí)使用模塊。我想在對(duì)話中使用按鈕,并獲取用戶選擇的按鈕的輸出。asynciotelethon@bot.on(events.NewMessage(incoming=True, pattern=r'start'))async def chatbot(event): sender = await event.get_sender(); SENDER = sender.id async with bot.conversation(SENDER) as conv: await conv.send_message('Select a button :') await conv.send_message('Yes or no?', buttons=[ Button.inline('Yes!', b'yes'), Button.inline('Nope', b'no') ]) if selected_button == 'yes' : # do something else: # do something使用文檔中給出的回調(diào)查詢,跳轉(zhuǎn)到 的函數(shù)。但不會(huì)回到函數(shù)。handler(event)events.CallbackQuery()convchatbot如何獲取所選按鈕信息并在功能中進(jìn)一步操作?chatbot
1 回答

海綿寶寶撒
TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊
從Telethon v1.11開始,您需要使用Conversation.wait_event
,這有點(diǎn)丑陋,但可以解決問題:
# Defined somewhere
def press_event(user_id):
return events.CallbackQuery(func=lambda e: e.sender_id == user_id)
...
# Later in your conversation
press = await conv.wait_event(press_event(SENDER))
添加回答
舉報(bào)
0/150
提交
取消