Python 在Telethon中,我想使用用户';只有在用户按下“设置我的地址”按钮后,才能使用s加密地址
但当我做event.text时,总是设置我的地址 这就是我正在做的Python 在Telethon中,我想使用用户';只有在用户按下“设置我的地址”按钮后,才能使用s加密地址,python,python-3.x,telegram-bot,telethon,Python,Python 3.x,Telegram Bot,Telethon,但当我做event.text时,总是设置我的地址 这就是我正在做的 @bot.on(events.NewMessage(pattern="/start")) async def start(event): await bot.send_message(event.chat.id, "testing" , buttons= [Button.text("set my address", resize=True, single
@bot.on(events.NewMessage(pattern="/start"))
async def start(event):
await bot.send_message(event.chat.id, "testing" , buttons=
[Button.text("set my address", resize=True, single_use=True)])
@bot.on(events.NewMessage(pattern="set my address"))
async def start(event):
print(event.text)
它在做你让它做的事 当用户按下按钮时,它会向bot发送一条消息,根据您的代码,该消息是“设置我的地址” 这将生成一个
NewMessage
事件,您可以为该事件设置一个处理程序。因此,您的event.text
将打印“设置我的地址”
要实现您希望实现的目标,您可以从这里开始:
@bot.on(events.NewMessage(pattern="/start"))
async def start(event):
await bot.send_message(event.chat.id, "testing" , buttons=
[Button.text("set my address", resize=True, single_use=True)])
@bot.on(events.NewMessage(pattern="set my address"))
async def set_my_address(event):
# Bot asks the user to send the address when s/he presses the button
await event.respond("Please send me your address")
@bot.on(events.NewMessage())
async def set_address(event):
'''
Now listen to the user's response using any method (for eg a regex pattern)
'''