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
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import asyncio
from typing import Optional
import asyncpg
@ -49,11 +50,18 @@ class Owner(Cog):
async def restart(self, ctx):
"""Restart the bot"""
# Close the database connection
try:
await asyncio.wait_for(self.bot.db.close(), timeout=1.0)
# Catch errors
except asyncio.TimeoutError:
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>")
self.bot.db.close()
await self.bot.db.wait_closed()
await self.bot.logout()
@command(name="reloadusers", hidden=True)

Loading…
Cancel
Save