Sapphire Scheduled Tasks | When do they launch after bot restarts?
I have a task that disables all message components. But this fails to run after bot restarts and trying to run it
Logs:
I setup it to load only on
postLogin
because in task I need to fetch channel & message, and obv I can't do that when bot is not ready.
Seems like ScheduledTaskPlugin
trying to run tasks that was on redis before postLogin step if you restart your bot
Is there a way to change that? :Hmm:
My custom plugin that loads this task to my bots:
Solution:Jump to solution
No. I mean don't call /register of the plugin and make a file similar to this and call it instead. You're already halfway there with your postLogin code. https://github.com/sapphiredev/plugins/blob/main/packages/scheduled-tasks/src/register.ts
GitHub
plugins/packages/scheduled-tasks/src/register.ts at main · sapphire...
Plugins for the Sapphire Framework. Contribute to sapphiredev/plugins development by creating an account on GitHub.
7 Replies
are you still calling the
/register
entrypoint of the plugin despite your own code?yep. because I need to register tasks that I need only for 1 bot
yeah you should remove that and replicate the code in your own register
you're currently registering it twice
this is example load function, by replicating you mean to add here logic to load tasks from their folder e.g.
scheduled-tasks
?Solution
No. I mean don't call /register of the plugin and make a file similar to this and call it instead. You're already halfway there with your postLogin code. https://github.com/sapphiredev/plugins/blob/main/packages/scheduled-tasks/src/register.ts
GitHub
plugins/packages/scheduled-tasks/src/register.ts at main · sapphire...
Plugins for the Sapphire Framework. Contribute to sapphiredev/plugins development by creating an account on GitHub.
What hook get called first
preGenericsInitialization
or postInitialization
? :Hmm:
Oh I managed to get it to work. Initially I just copied all code from your's register.ts
and put it to postLogin
hook. And nothing happens. I just saw the description to stores.register
method, that you need to register store as early as possible. I leave to the postInit
stage and now everything works!
Final look of the custom plugin:
https://github.com/sapphiredev/framework/blob/main/src/lib/SapphireClient.ts#L200-L362 you can follow the logic here