#Having problems with v5 using client.fetch_channel()

1 messages · Page 1 of 1 (latest)

wind heath
#

Hello guys, i've managed to make my Flask app run with my bot using the code below:

# Create two threads, one for the Flask app and one for the Discord bot
        flask_thread = threading.Thread(target=run_flask)
        discord_thread = threading.Thread(target=run_discord)

        # Start both threads
        discord_thread.start()
        flask_thread.start()
        

        # Wait for both threads to finish
        flask_thread.join()
        discord_thread.join()

So, Flask and bot starts successfully with no problem.

So then i created the following Flask route:

async def test():
    data = request.get_json()
    ch_id = 975470215578132531
    ch = await bot.fetch_channel(ch_id)
    await ch.send(f"{data}")
    return "", 200

Which should work perfectly.
But i'm having the following error:
RuntimeError: Timeout context manager should be used inside a task
Could any of you gimme a hand on that please?

steady wyvernBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

mint mason
#

you cant mix flask and asyncio like that

#

especially with your bot and your flask app running on completely different threads

wind heath
#

i'm kinda new to this "async" thing

#

could gimme a hand on that?

mint mason
#

not really - thats quite out-of-scope of this server

Your best bet is to learn how to make an async app first, before trying to mix flask and i.py

realpython has an alright guide on asyncio https://realpython.com/async-io-python/

and the python discord server is a good place for general python help

wind heath
#

okay, ill take a look on that, thx alot 🙂

mint mason
#

np. best of luck