EmperorFred/discord_bot/cogs/restart.py

26 lines
815 B
Python
Raw Permalink Normal View History

2025-12-06 02:21:47 +00:00
import asyncio
from discord.ext import commands as discord_commands
from libs.Cog import Cog
class RestartCog(Cog):
"""Owner-only administrative cogs for managing the bot lifecycle."""
@discord_commands.command(name="restart")
@discord_commands.is_owner()
async def restart(self, ctx: discord_commands.Context):
"""Restart the Discord bot without stopping the whole app."""
controller = getattr(ctx.bot, "restart_controller", None)
if not controller:
await ctx.send("Restart controller not available.")
return
await ctx.send("Restarting Discord bot...")
controller.request()
await asyncio.sleep(0.2)
await ctx.bot.close()
async def setup(bot: discord_commands.Bot) -> None:
await bot.add_cog(RestartCog(bot))