ask()¶
- async Client.ask()¶
Send a message and wait for the answer to it.
Shortcut for
send_message()followed bylisten(). The returned update carries the prompt assent_message.Usable by Users Bots- Parameters:
chat_id (
int|str| List ofint|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 raisingListenerTimeout. Defaults to the client’slistener_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 ofint|str, optional) – User the answer has to come from.message_id (
int| List ofint, optional) – Message the answer has to belong to.inline_message_id (
str| List ofstr, 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 assent_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}")