diff --git a/events.py b/events.py index a50f7ac..7aa87d3 100644 --- a/events.py +++ b/events.py @@ -1,3 +1,6 @@ +import asyncio +import threading + import commands import core import tasks @@ -5,7 +8,23 @@ from state import client async def on_ready(): - await tasks.check_idle() + threading.Thread( + name="cleanup", + target=asyncio.run_coroutine_threadsafe, + args=( + tasks.cleanup(), + client.loop, + ), + ).start() + + threading.Thread( + name="check_idle", + target=asyncio.run_coroutine_threadsafe, + args=( + tasks.check_idle(), + client.loop, + ), + ).start() async def on_message(message): diff --git a/tasks.py b/tasks.py index 53a965c..e3795aa 100644 --- a/tasks.py +++ b/tasks.py @@ -6,16 +6,6 @@ import disnake from state import client, last_used, players -async def check_idle(): - while True: - await asyncio.sleep(3600) - - if time.time() - last_used >= 3600: - await client.change_presence(status=disnake.Status.idle) - else: - await client.change_presence(status=disnake.Status.online) - - async def cleanup(): while True: await asyncio.sleep(3600) @@ -26,3 +16,13 @@ async def cleanup(): targets.append(id) for target in targets: del players[target] + + +async def check_idle(): + while True: + await asyncio.sleep(3600) + + if time.time() - last_used >= 3600: + await client.change_presence(status=disnake.Status.idle) + else: + await client.change_presence(status=disnake.Status.online)