"Timeout context manager should be used inside a task" Discord Bot Error

Viewed 220

So, this is my first post for help, so bear with me if I do something wrong. Basically, I'm getting the error above by trying to run 'await'. Ill start off with my code.

#main.py
t = threading.Thread(target=examplefunction, args=(msgcontent,channel )) 
t.start()

I start off by calling the function with a thread. To sum it up this gathers information. Note that all the code isn't the full program.

#examplefunction.py
 loop = asyncio.new_event_loop()
 asyncio.set_event_loop(loop)
    
 loop.run_until_complete(examplefunction2(content))
 loop.close()

Then before the function ends, it calls upon another function to send the data, to avoid errors (just trust me here)

#examplefunction2.py
bot = discord.Client()

@bot.event
async def mcsending(content):
  channel = content
  print(channel)
  await channel.send('here')

Then this is where the issue starts. 'Await' raises the error in the title.

EDIT: I figured out my error if anyone is intrested.

#examplefunction.py
bot.loop.create_task(examplefunction2(content))

simply replaced 'loop.until_complete' with that

0 Answers
Related