title: Is there any way to stop and then start a discord.py bot without having to restart the whole py file?
body: <p>According to discord.py's discord server as well as their docs you'd need to restart the whole py file after using 'bot.close()' since it disconnects from their api. Unfortunately I'm trying to create a launcher and it wouldn't really be ideal to restart the whole launcher to restart the bot, does anyone know any 'hacky' ways of starting up a discord.py bot after using 'bot.close()'? it doesn't have to be pretty, just needs to remotely work. Any suggestions/tips would be greatly appreciated.</p>
  <pre><code>    @asyncSlot()
      async def on_btnStartBot_clicked(self):
          self.pushButton_startBot.setEnabled(False)
          if self.isBotRunning == False:
              self.statusbar.showMessage(&quot;Starting Bot...&quot;)
              try:
                  if isinstance(cfg[&quot;bot&quot;][&quot;token&quot;], str) and cfg[&quot;bot&quot;][&quot;token&quot;] != &quot;&quot;:
                      await bot.start(cfg[&quot;bot&quot;][&quot;token&quot;])
                  elif isinstance(cfg[&quot;bot&quot;][&quot;token&quot;], list) and not all(token == &quot;&quot; for token in cfg[&quot;bot&quot;][&quot;token&quot;]):
                      def first_token():
                          for t in cfg[&quot;bot&quot;][&quot;token&quot;]:
                              if t != &quot;&quot;:
                                  return t
                      await bot.start(first_token())
                  else:
                      terminal.log(&quot;CRITICAL&quot;, f&quot;No token was provided in '{utils.config.CONFIG_PATH}'&quot;)
              except Exception as e:
                  self.statusbar.showMessage(str(e))
          else:
              self.statusbar.showMessage(&quot;Stopping Bot...&quot;)
              await bot.close()
              self.plainTextEdit_botTerminal.clear()
              while not bot.is_closed():
                  print('Not Yet Closed')
              if bot.is_closed():
                  print(&quot;Closed&quot;)
                  self.statusbar.showMessage(&quot;Bot Has Been Stopped...&quot;)
                  self.pushButton_startBot.setText(&quot;Start Bot&quot;)
                  self.isBotRunning = False
                  await asyncio.sleep(1)
                  self.pushButton_startBot.setEnabled(True)
  </code></pre>