title: How to disconnect telegram client?
body: <p>Im trying to write a script in python that listen &quot;first reply&quot; of a bot and then exits. So, I create a client instance and then send a msg to Bot and now I want to record only first reply of bot (upcoming replies can ignored), and save bot reply to Reply variable. Now how to exit from listener mode so that I can do other stuffs after getting reply. I tried <strong>client.disconnect()</strong> and <strong>client.disconnected()</strong> but now working or maybe I don't know proper use of these method. I'm new to telethon APIs.</p>
  <blockquote>
  <p>When I run this script, a msg from my telegram is sent to
  bot(<strong>BotFather</strong>) and then bot send a reply</p>
  </blockquote>
  <p>Reply from bot father</p>
  <blockquote>
  <p>I can help you create and manage Telegram bots. If you're new to the
  Bot API, please see the manual (<a href="https://core.telegram.org/bots" rel="nofollow noreferrer">https://core.telegram.org/bots</a>).</p>
  <p>You can control me by sending these commands:</p>
  <p>/newbot - create a new bot /mybots - edit your bots [beta]</p>
  <p>Edit Bots /setname - change a bot's name /setdescription - change bot
  description /setabouttext - change bot about info /setuserpic - change
  bot profile photo /setcommands - change the list of commands
  /deletebot - delete a bot</p>
  <p>Bot Settings /token - generate authorization token /revoke - revoke
  bot access token /setinline - toggle inline mode
  (<a href="https://core.telegram.org/bots/inline" rel="nofollow noreferrer">https://core.telegram.org/bots/inline</a>) /setinlinegeo - toggle inline
  location requests
  (<a href="https://core.telegram.org/bots/inline#location-based-results" rel="nofollow noreferrer">https://core.telegram.org/bots/inline#location-based-results</a>)
  /setinlinefeedback - change inline feedback
  (<a href="https://core.telegram.org/bots/inline#collecting-feedback" rel="nofollow noreferrer">https://core.telegram.org/bots/inline#collecting-feedback</a>) settings
  /setjoingroups - can your bot be added to groups? /setprivacy - toggle
  privacy mode (<a href="https://core.telegram.org/bots#privacy-mode" rel="nofollow noreferrer">https://core.telegram.org/bots#privacy-mode</a>) in groups</p>
  <p>Games /mygames - edit your games
  (<a href="https://core.telegram.org/bots/games" rel="nofollow noreferrer">https://core.telegram.org/bots/games</a>) [beta] /newgame - create a new
  game (<a href="https://core.telegram.org/bots/games" rel="nofollow noreferrer">https://core.telegram.org/bots/games</a>) /listgames - get a list of
  your games /editgame - edit a game /deletegame - delete an existing
  game</p>
  </blockquote>
  <p>and this reply got assigned in Reply variable</p>
  <blockquote>
  <p>but my scripts
  still listening for other upcoming events. is there any method from
  which I can close this connection.</p>
  </blockquote>
  <pre><code>import random
  import traceback
  import configparser
  from telethon import TelegramClient, events, sync
  from telethon.errors import SessionPasswordNeededError
  from telethon.errors.rpcerrorlist import PeerFloodError
  from telethon.tl.functions.channels import InviteToChannelRequest
  from telethon.tl.functions.messages import GetDialogsRequest,GetHistoryRequest
  from telethon.tl.types import InputPeerEmpty, InputPeerChannel, InputPeerUser, PeerChannel
  
  api_id =  #Api_ID
  api_hash = #Api_Hash
  phone = #session
  client = TelegramClient(phone, api_id, api_hash)
  Reply = ' '
  
  @client.on(events.NewMessage(chats='https://t.me/BotFather'))
  async def NewMessageListener(event):
      Reply = event.message.message
  
  with client:
      client.send_message(&quot;https://t.me/BotFather&quot;, &quot;/start&quot;)
      client.run_until_disconnected()
  
      # Disconnect client to stop run_until_disconnected()
  
  # Do other stuff!!!
  </code></pre>