fix forcestop and prevent botstop if server running

This commit is contained in:
Nayan
2025-08-25 22:33:10 -04:00
parent 2a45bc558c
commit dee20374f2

17
bot.py
View File

@@ -211,7 +211,7 @@ async def _stop_server_internal(ctx, servername, method):
if method == "stop": if method == "stop":
command_to_send = 'stop\n' command_to_send = 'stop\n'
elif method == "forcestop": elif method == "forcestop":
command_to_send = "$'\\003'" # Ctrl+C command_to_send = "$'\003'" # Ctrl+C
else: else:
await ctx.send("Invalid stop method.") await ctx.send("Invalid stop method.")
return return
@@ -496,18 +496,11 @@ async def botstop(ctx):
''' '''
global active_server, active_server_pipe_task global active_server, active_server_pipe_task
if active_server_pipe_task: if active_server is not None:
active_server_pipe_task.cancel() await ctx.send(f"Server running, please stop the server before stopping the bot.")
try: return
await active_server_pipe_task # Await to ensure it cleans up
except asyncio.CancelledError:
pass # Expected
active_server_pipe_task = None
if active_server:
await _delete_named_pipe(active_server) # Delete the pipe file
await bot.close() await bot.close()
print("Bot stopped.")
bot.run(TOKEN) bot.run(TOKEN)