#Running add_reaction outside await function

1 messages · Page 1 of 1 (latest)

lone ocean
#

Hi. My schedule doest support Async, so i want to run await without async. Im using: bot.loop.create_task(moji.add_reaction(":one:")) Now it doesn't work for add_reaction. It it possible to do? I really like the scheduler tbh.
Schedule code: schedule.every().day.at("09:52").do(get_question)

smoky agate
#

How come it doesn't work

lone ocean
#
moji =  bot.loop.create_task(bot.get_channel(979395372214538304).send(embed=embed))
if get_random_poll[3] != "None":
       bot.loop.create_task(moji.add_reaction("1️⃣"))

= AttributeError: '_asyncio.Task' object has no attribute 'add_reaction'

rich oar
lone ocean
rich oar
#

oh thats sending

lone ocean
rich oar
#

u just not using async or something?

lone ocean
#

schedule.every().day.at("18:30").do(get_question)
get_question is the function, cant add await before it

rich oar
#

why not use a async scheduler

lone ocean
#

But did not run, even the demo on that page doesnt work

cerulean hinge
#

fetch is async

#

you don't need a task to use get_channel here

lone ocean
#

Ah okey

lone ocean
#

There isnt a work around?

lone ocean
cerulean hinge
#

your issue is that create_task returns an asyncio.Task, not whatever the coroutine inside returns

#

just make a helper function that does all three things (get emoji, send embed, add reaction), then call that one function inside a task

lone ocean
#

Ah okey, will try that later when i'm behind the pc again!

smoky agate
#

Or get an async scheduler

#

:)

cerulean hinge
#

^

rich oar
#

apscheduler

smoky agate
#

Because working with .create_task within sync context is pain

cerulean hinge
#

using an async scheduler will be better in the long run anyways

lone ocean
#

Check!