ask()

async Client.ask()

Send a message and wait for the answer to it.

Shortcut for send_message() followed by listen(). The returned update carries the prompt as sent_message.

Usable by Users Bots
Parameters:
  • chat_id (int | str | List of int | str) – Chat to send the question to. When a list is given, the question goes to the first one and any of them may answer.

  • text (str) – Text of the question.

  • filters (Filter, optional) – Extra filter the answer has to pass.

  • listener_type (ListenerTypes, optional) – Kind of update to wait for. Defaults to a new message.

  • timeout (float, optional) – Seconds to wait before raising ListenerTimeout. Defaults to the client’s listener_timeout (300s).

  • unallowed_click_alert (bool | str, optional) – For callback query listeners, answer clicks coming from a user this listener does not expect. Pass a string to set the text.

  • user_id (int | str | List of int | str, optional) – User the answer has to come from.

  • message_id (int | List of int, optional) – Message the answer has to belong to.

  • inline_message_id (str | List of str, optional) – Inline message the answer has to belong to.

  • kwargs – Any other argument accepted by send_message().

Returns:

Message | CallbackQuery – The answer, with the prompt attached as sent_message.

Raises:
  • ListenerTimeout – In case nobody answered in time.

  • ListenerStopped – In case the listener was stopped, or the client is.

  • ListenerLimitReached – In case no listener slot was available.

Example

answer = await app.ask(chat_id, "What is your name?", timeout=60)
await answer.reply(f"Hello {answer.text}")