I'm trying to make a command for a discord bot which make the bot perform actions that can be very long. So I want to send a message to inform the user before each key step.
However, due to network limitations, sending a message can take time, therefore slowing even more the program.
working code
When I call function which return no value, it works perfectly fine the following way :
import discord
import requests
import asyncio
with requests.Session() as session:
await asyncio.gather(
ctx.send("Connecting to the server"),
init_session(session)
)
TypeError with a dictionnary
But, the problem is that later on, I use a fonction which returns a dictionnary :
result = await asyncio.gather(
ctx.send("Connecting to the server"),
get_dict(session)
)
Then, it gives me the following error : asyncio gather TypeError: unhashable type: 'dict'
RunTimeError with a Thread
I also tried to execute the send
function in another thread :
t = threading.Thread(target=asyncio.run, args=[ctx.send("Getting result")])
t.start()
But then I have yet another error : RuntimeError: Task <Task pending name='Task-20' coro=<Messageable.send() running at [my discord library directory]> cb=[_run_until_complete_cb() at [my asyncio directory]\base_events.py:184]> got Future <Future pending> attached to a different loop
So I would be really thankful if someone know a better way.