如何在图片上写下用户回复的等待?它需要像这样:
#!python3
@dp.message_handler(commands["start"]):
async def start(message: types.Message):
bot.reply("Send me your name")
name = #Here need func that will await message发布于 2021-12-01 13:12:38
你应该使用FSM,这是a的一个内置特性。
您的案例示例:
from aiogram import Bot, Dispatcher, types
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
bot = Bot(token='BOT TOKEN HERE')
# Don't forget to use storage, otherwise answers won't be saved.
# You can find all supported storages here:
# https://github.com/aiogram/aiogram/tree/dev-2.x/aiogram/contrib/fsm_storage
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)
class Form(StatesGroup):
name = State()
@dp.message_handler(commands=['start'])
async def start(message: types.Message):
"""Conversation entrypoint"""
# Set state
await Form.name.set()
await message.reply("Send me your name")
# You can use state='*' if you want to handle all states
@dp.message_handler(state='*', commands=['cancel'])
async def cancel_handler(message: types.Message, state: FSMContext):
"""Allow user to cancel action via /cancel command"""
current_state = await state.get_state()
if current_state is None:
# User is not in any state, ignoring
return
# Cancel state and inform user about it
await state.finish()
await message.reply('Cancelled.')
@dp.message_handler(state=Form.name)
async def process_name(message: types.Message, state: FSMContext):
"""Process user name"""
# Finish our conversation
await state.finish()
await message.reply(f"Hello, {message.text}") # <-- Here we get the name它看起来是这样的:

aiogram FSM的Official documentation相当糟糕,但是有an example可以帮助你发现FSM所拥有的几乎所有东西。
https://stackoverflow.com/questions/69846020
复制相似问题