Scheduling an async function using the Schedule library. (Using discord.py rewrite)

心已入冬 提交于 2020-01-04 05:13:11

问题


My last post got incorrectly marked as duplicate. I am not trying to do asyncio.sleep, becuase it is too inaccurate over the space of weeks. I need the schedule library.

I found a similar thread: How can I run an async function using the schedule library? This did not help me, or the OP of the thread. I ended up with the same error as him, which he stated in a comment of the only answer.

My goal is to run a function (which must be async) every x seconds. (Set to seconds for testing purposes. The finished code will use days.)

My simplified code to try do this:

@bot.event
async def schedTest():
    print("Scheduled Message Here")

@bot.command(pass_context=True)
async def announcements(ctx):
    schedule.every(1).seconds.do(
        bot.loop.call_soon_threadsafe, schedTest)

After executing the command announcements,the result of this is nothing. No error or prints in the output.

This is not the same issue as the thread that this was marked as duplicate as. I am trying to get the schedule library to work, not asyncio.sleep. Sleep is not accurate over the duration of a week.

If it isn't possible, could someone advise a way to do a scheduled function accurate to a few minutes over several weeks? As this is what I'm pretty much trying to achieve.

来源:https://stackoverflow.com/questions/52131356/scheduling-an-async-function-using-the-schedule-library-using-discord-py-rewri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!