From f9504a1f86bd9b63bb78a26f6d06afa63036affc Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Wed, 11 Jan 2023 11:04:39 +0100 Subject: [PATCH] separate bot instance creation and start --- truthseeker/__init__.py | 4 +++- truthseeker/discord_bot.py | 14 ++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/truthseeker/__init__.py b/truthseeker/__init__.py index 08f3077..7f3c9de 100644 --- a/truthseeker/__init__.py +++ b/truthseeker/__init__.py @@ -15,9 +15,11 @@ class TruthSeekerApp(flask.Flask): self.socketio_app = SocketIO(self) + self.discord_bot = discord_bot.DiscordBot() token = self.get_discord_bot_token() if token: - self.discord_bot = discord_bot.init_bot(token) + pass + self.discord_bot.start(token) else: print("No token set. Not starting discord bot") diff --git a/truthseeker/discord_bot.py b/truthseeker/discord_bot.py index bc86c76..9d42acb 100644 --- a/truthseeker/discord_bot.py +++ b/truthseeker/discord_bot.py @@ -6,14 +6,6 @@ import asyncio async def empty_coro(): return -def init_bot(token): - discord_bot = DiscordBot() - - thr = threading.Thread(target=discord_bot.__run__, args=(token,)) - thr.start() - - return discord_bot - class DiscordBot: def __init__(self): self.bot = discord.Client(intents=discord.Intents.default()) @@ -33,8 +25,10 @@ class DiscordBot: else: print("Could not find channel #bot") - def __run__(self, token): - self.bot.run(token) + def start(self, token): + thr = threading.Thread(target=self.bot.run, args=(token,)) + thr.start() + return thr def API(func): def decorator(self, *args, **kwargs):