Answer the question
In order to leave comments, you need to log in
How to properly run a Discord bot in a stream?
I am working with PyQt5 . You need to run the Discord bot along with the rest of the thread.
def BOT_RUN():
print("FUNC: BOT_RUN")
bot.run(config.BOT_TOKEN)
class WorkThread(QtCore.QThread):
threadSignal = QtCore.pyqtSignal(int)
def __init__(self):
super().__init__()
def run(self):
i = ''
self.msleep(300)
self.threadSignal.connect(BOT_RUN)
self.threadSignal.connect(CHECK_CSVS)
self.threadSignal.connect(SERVER_MONITORING)
self.threadSignal.emit(i)
self.threadSignal.disconnect(CHECK_CSVS)
self.threadSignal.connect(BOT_RUN)
- fires and starts the bot, but the application closes. As if he launched a bot and that's enough for him. print("FUNC: функция")
to understand if other functions are launched. FUNC: BOT_RUN
PS C:\Users\...\Desktop\LOGGER>
Answer the question
In order to leave comments, you need to log in
def START():
loop = asyncio.new_event_loop()
try:
loop.run_until_complete(bot.start(config.BOT_TOKEN))
except KeyboardInterrupt:
loop.run_until_complete(bot.close())
finally:
loop.close()
class WorkThread(QtCore.QThread):
threadSignal = QtCore.pyqtSignal(int)
def __init__(self):
super().__init__()
def run(self):
i = ''
self.msleep(300)
self.threadSignal.connect(START)
self.threadSignal.emit(i)
I don't know how threadSignal.connect() works, but I do know that bot.run() won't return until the bot has exited.
Those. from the BOT_RUN function, the flow of control will not return for a very long time.
Perhaps it's worth rescheduling which thread does what? Allocate a separate thread for bot.run()?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question