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.socketio_app = SocketIO(self)
|
||||||
|
|
||||||
|
self.discord_bot = discord_bot.DiscordBot()
|
||||||
token = self.get_discord_bot_token()
|
token = self.get_discord_bot_token()
|
||||||
if token:
|
if token:
|
||||||
self.discord_bot = discord_bot.init_bot(token)
|
pass
|
||||||
|
self.discord_bot.start(token)
|
||||||
else:
|
else:
|
||||||
print("No token set. Not starting discord bot")
|
print("No token set. Not starting discord bot")
|
||||||
|
|
||||||
|
|||||||
@ -6,14 +6,6 @@ import asyncio
|
|||||||
async def empty_coro():
|
async def empty_coro():
|
||||||
return
|
return
|
||||||
|
|
||||||
def init_bot(token):
|
|
||||||
discord_bot = DiscordBot()
|
|
||||||
|
|
||||||
thr = threading.Thread(target=discord_bot.__run__, args=(token,))
|
|
||||||
thr.start()
|
|
||||||
|
|
||||||
return discord_bot
|
|
||||||
|
|
||||||
class DiscordBot:
|
class DiscordBot:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.bot = discord.Client(intents=discord.Intents.default())
|
self.bot = discord.Client(intents=discord.Intents.default())
|
||||||
@ -33,8 +25,10 @@ class DiscordBot:
|
|||||||
else:
|
else:
|
||||||
print("Could not find channel #bot")
|
print("Could not find channel #bot")
|
||||||
|
|
||||||
def __run__(self, token):
|
def start(self, token):
|
||||||
self.bot.run(token)
|
thr = threading.Thread(target=self.bot.run, args=(token,))
|
||||||
|
thr.start()
|
||||||
|
return thr
|
||||||
|
|
||||||
def API(func):
|
def API(func):
|
||||||
def decorator(self, *args, **kwargs):
|
def decorator(self, *args, **kwargs):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user