Closing connection properly before shutting down bot

pull/8/head
sgoudham 4 years ago
parent 4d832ee799
commit f2f20cd1e8

@ -13,6 +13,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
import asyncio
from typing import Optional from typing import Optional
import asyncpg import asyncpg
@ -49,12 +50,19 @@ class Owner(Cog):
async def restart(self, ctx): async def restart(self, ctx):
"""Restart the bot""" """Restart the bot"""
await self.bot.generate_embed(ctx, desc="**Success Senpai!" # Close the database connection
"\nMy Reboot Had No Problems** <a:ThumbsUp:737832825469796382>") try:
await asyncio.wait_for(self.bot.db.close(), timeout=1.0)
self.bot.db.close() # Catch errors
await self.bot.db.wait_closed() except asyncio.TimeoutError:
await self.bot.logout() await self.bot.generate_embed(ctx, desc="**Database Connection Timed Out!")
# Shutdown the bot
else:
await self.bot.generate_embed(ctx, desc="**Success Senpai!"
"\nMy Reboot Had No Problems** <a:ThumbsUp:737832825469796382>")
await self.bot.logout()
@command(name="reloadusers", hidden=True) @command(name="reloadusers", hidden=True)
@is_owner() @is_owner()

Loading…
Cancel
Save