I have 2 files, each running on different threads currently. One for the main file which runs a flask website, one for a discord bot in a seperate thread. I am trying to call a async method on the discord side to send a message to a user once a request is received.
#IN DISCORD FILE (discbot.py)
client = discord.Client()
async def registerSuccess(state, btag):
...
await client.wait_until_ready()
guilds = client.fetch_guilds()
async for guild in guilds:
name = await guild.name
print(name)
#IN FLASK/MAIN FILE (main.py)
@app.route("/oauth", methods=["POST", "GET"])
def oauth():
...
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
#loop.run_until_complete(discbot.registerSuccess(state, btag)) - Did not work
#asyncio.run(discbot.registerSuccess(state, btag)) - Did not work
# Both of these two above gave me:
#
# "RuntimeError: Task <Task pending coro=#<registerSuccess() running at
# /home/container/arcanabot.py:78> cb=[_run_until_complete_cb() at
# /usr/local/lib/python3.7/asyncio/base_events.py:157]> got Future
# <Future pending> attached to a different loop"
asyncio.run_coroutine_threadsafe(discbot.registerSuccess(state, btag), loop) - Did not work
#This one never managed to run the function at all
I am not very familiar with async functions and asyncio and have had no success with anything above.