separate bot instance creation and start
This commit is contained in:
parent
dd727310f7
commit
f9504a1f86
@ -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")
|
||||
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user