Skip to main content
added 803 characters in body
Source Link
Bo. Ga.
  • 148
  • 1
  • 5
  • 12

After @PythonPro recommendations i've changed on_ready function:

 G_hasLaunched = False @client.event async def on_ready(): global G_hasLaunched print('Logged in as {0.user}'.format(client)) if G_hasLaunched == False: G_hasLaunched = True try: print("creating tasks") asyncio.ensure_future(taskOne()) asyncio.ensure_future(taskTwo()) asyncio.ensure_future(taskThree()) asyncio.ensure_future(taskFour()) except BaseException as err: logger.logger('Unexpected error > "' + str(err) + '" / "' + str(type(err)) + '"') raise 

Still trying to figure out if it fixed the whole mess


After @PythonPro recommendations i've changed on_ready function:

 G_hasLaunched = False @client.event async def on_ready(): global G_hasLaunched print('Logged in as {0.user}'.format(client)) if G_hasLaunched == False: G_hasLaunched = True try: print("creating tasks") asyncio.ensure_future(taskOne()) asyncio.ensure_future(taskTwo()) asyncio.ensure_future(taskThree()) asyncio.ensure_future(taskFour()) except BaseException as err: logger.logger('Unexpected error > "' + str(err) + '" / "' + str(type(err)) + '"') raise 

Still trying to figure out if it fixed the whole mess

added 7 characters in body
Source Link
Bo. Ga.
  • 148
  • 1
  • 5
  • 12

I have to mention, that taskOne() can vary quiet a lot depending on the stuff it processes, can go for 5from 1 to 20minutesnear 20 minutes long.

I have to mention, that taskOne() can vary quiet a lot depending on the stuff it processes, can go for 5 to 20minutes long.

I have to mention, that taskOne() can vary quiet a lot depending on the stuff it processes, can go from 1 to near 20 minutes long.

added 210 characters in body
Source Link
Bo. Ga.
  • 148
  • 1
  • 5
  • 12
 import discord import asyncio # import settingsDB import logger # import module_one import module_two import module_three import module_four [...] client = discord.Client() botToken = settingsDB.getBotSetting("DiscordToken") # on_ready event stuff @client.event async def on_ready(): # stuff # [...] # on_message event stuff @client.event async def on_message(message): # stuff # [...] # Tasks functions async def taskOne(): while True: cycle = settingsDB.getBotSetting("taskOne_Cycle") # calling for stuff in module_one.py # stuff # [...] await asyncio.sleep(int(cycle)) async def taskTwo(): while True: cycle = settingsDB.getBotSetting("taskTwo_Cycle") # calling for stuff in module_two.py # stuff # [...] await asyncio.sleep(int(cycle)) async def taskThree(): while True: cycle = settingsDB.getBotSetting("taskThree_Cycle") # calling for stuff in module_three.py # stuff # [...] await asyncio.sleep(int(cycle)) async def taskFour(): while True: cycle = settingsDB.getBotSetting("taskFour_Cycle") # calling for stuff in module_four.py # stuff # [...] await asyncio.sleep(int(cycle)) client.run(botToken) 

settingsDB refers to settingsDB.py where all the function querying my DB are stored and can change depending on user inputs updated via another source not related with Discord bot (via website PHP).

logger refers to logger.py where i'm wrting into a txt file stuff that i want as logs.

Under on_ready event i wrote:

 @client.event async def on_ready(): print('Logged in as {0.user}'.format(client))    loop = asyncio.get_event_loop() try: asyncio.ensure_future(taskOne()) asyncio.ensure_future(taskTwo()) asyncio.ensure_future(taskThree()) asyncio.ensure_future(taskFour()) except BaseException as err: logger.logger('Unexpected error > "' + str(err) + '" / "' + str(type(err)) + '"') raise 
 import discord import asyncio # import settingsDB # import module_one import module_two import module_three import module_four [...] client = discord.Client() botToken = settingsDB.getBotSetting("DiscordToken") # on_ready event stuff @client.event async def on_ready(): # stuff # [...] # on_message event stuff @client.event async def on_message(message): # stuff # [...] # Tasks functions async def taskOne(): while True: cycle = settingsDB.getBotSetting("taskOne_Cycle") # calling for stuff in module_one.py # stuff # [...] await asyncio.sleep(int(cycle)) async def taskTwo(): while True: cycle = settingsDB.getBotSetting("taskTwo_Cycle") # calling for stuff in module_two.py # stuff # [...] await asyncio.sleep(int(cycle)) async def taskThree(): while True: cycle = settingsDB.getBotSetting("taskThree_Cycle") # calling for stuff in module_three.py # stuff # [...] await asyncio.sleep(int(cycle)) async def taskFour(): while True: cycle = settingsDB.getBotSetting("taskFour_Cycle") # calling for stuff in module_four.py # stuff # [...] await asyncio.sleep(int(cycle)) client.run(botToken) 

Under on_ready event i wrote:

 @client.event async def on_ready(): print('Logged in as {0.user}'.format(client))    loop = asyncio.get_event_loop() try: asyncio.ensure_future(taskOne()) asyncio.ensure_future(taskTwo()) asyncio.ensure_future(taskThree()) asyncio.ensure_future(taskFour()) except BaseException as err: logger.logger('Unexpected error > "' + str(err) + '" / "' + str(type(err)) + '"') raise 
 import discord import asyncio # import settingsDB import logger # import module_one import module_two import module_three import module_four [...] client = discord.Client() botToken = settingsDB.getBotSetting("DiscordToken") # on_ready event stuff @client.event async def on_ready(): # stuff # [...] # on_message event stuff @client.event async def on_message(message): # stuff # [...] # Tasks functions async def taskOne(): while True: cycle = settingsDB.getBotSetting("taskOne_Cycle") # calling for stuff in module_one.py # stuff # [...] await asyncio.sleep(int(cycle)) async def taskTwo(): while True: cycle = settingsDB.getBotSetting("taskTwo_Cycle") # calling for stuff in module_two.py # stuff # [...] await asyncio.sleep(int(cycle)) async def taskThree(): while True: cycle = settingsDB.getBotSetting("taskThree_Cycle") # calling for stuff in module_three.py # stuff # [...] await asyncio.sleep(int(cycle)) async def taskFour(): while True: cycle = settingsDB.getBotSetting("taskFour_Cycle") # calling for stuff in module_four.py # stuff # [...] await asyncio.sleep(int(cycle)) client.run(botToken) 

settingsDB refers to settingsDB.py where all the function querying my DB are stored and can change depending on user inputs updated via another source not related with Discord bot (via website PHP).

logger refers to logger.py where i'm wrting into a txt file stuff that i want as logs.

Under on_ready event i wrote:

 @client.event async def on_ready(): print('Logged in as {0.user}'.format(client)) try: asyncio.ensure_future(taskOne()) asyncio.ensure_future(taskTwo()) asyncio.ensure_future(taskThree()) asyncio.ensure_future(taskFour()) except BaseException as err: logger.logger('Unexpected error > "' + str(err) + '" / "' + str(type(err)) + '"') raise 
Source Link
Bo. Ga.
  • 148
  • 1
  • 5
  • 12
Loading