conversation.py

 1import asyncio
 2from bale import Bot, Message
 3
 4client = Bot(token="Your Token")
 5
 6@client.event
 7async def on_ready():
 8    print(client.user, "is Ready!")
 9
10@client.event
11async def on_message(message: Message):
12    if message.content == '/give_name_without_timeout':
13        await message.reply('what is your name?')
14        def answer_checker(m: Message):
15            return message.author == m.author and bool(message.text)
16        answer_obj: Message = await client.wait_for('message', check=answer_checker)
17        return await answer_obj.reply(f'Your name is {answer_obj.content}')
18
19    elif message.content == '/give_name_with_timeout':
20        await message.reply('what is your name?')
21
22        def answer_checker(m: Message):
23            return message.author == m.author and bool(message.text)
24        try:
25            answer_obj: Message = await client.wait_for('message', check=answer_checker, timeout=10.0)
26        except asyncio.TimeoutError:
27            return await message.chat.send('No response received; Therefore, the operation was canceled.')
28        else:
29            return await answer_obj.reply(f'Your name is {answer_obj.content}')
30
31client.run()