def run_bot():
is_running = True
while is_running:
try:
main_logger.info('Starting bot...')
client.loop.run_until_complete(client.start(token)) # Start the bot
except KeyboardInterrupt: # It has been stopped?
client.loop.run_until_complete(client.logout())
pending = asyncio.Task.all_tasks()
gathered = asyncio.gather(*pending)
try:
gathered.cancel()
client.loop.run_until_complete(gathered)
gathered.exception()
finally:
is_running = False
except discord.ConnectionClosed as e: # We lost connection?
main_logger.exception(e)
main_logger.info('Retrying connection in 5 seconds...')
time.sleep(5)
finally:
client.loop.close()
评论列表
文章目录