separate bot instance creation and start

This commit is contained in:
Thomas Rubini 2023-01-11 11:04:39 +01:00
parent dd727310f7
commit f9504a1f86
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
2 changed files with 7 additions and 11 deletions

View File

@ -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")

View File

@ -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):