@sapphire/plugin-scheduled-tasks fails completely

Hello, I am looking to use the @sapphire/plugin-scheduled-tasks so I made a test script based off the documentation on the Github page. I rewritten the script in commonjs as I use that instead of ts. It does does not work well. It immediately fires instead of the duration as specified, it also doesn't pass any payload variables specified. Would I happen to be doing something wrong?
# The console output, which is empty
Iran {}
# The console output, which is empty
Iran {}
// This starts a task.
this.container.tasks.create('tempBan', { guild: member.guild, member }, duration);
// This starts a task.
this.container.tasks.create('tempBan', { guild: member.guild, member }, duration);
// The main thing itself
const { ScheduledTask } = require('@sapphire/plugin-scheduled-tasks');

class ManualTask extends ScheduledTask {
constructor(context, options) {
super(context, {
...options
});
}
async run(payload) {
console.log(`Iran`, payload);
}
}

module.exports = {
ManualTask,
}
// The main thing itself
const { ScheduledTask } = require('@sapphire/plugin-scheduled-tasks');

class ManualTask extends ScheduledTask {
constructor(context, options) {
super(context, {
...options
});
}
async run(payload) {
console.log(`Iran`, payload);
}
}

module.exports = {
ManualTask,
}
Solution:
First of all, create takes 2 parameters and you provided 3. The proper syntax is this.container.tasks.create({ name: 'name', payload: { huilde: member.guild, member }}, { delay: 9999999999 })
Jump to solution
7 Replies
Solution
Favna
Favna4mo ago
First of all, create takes 2 parameters and you provided 3. The proper syntax is this.container.tasks.create({ name: 'name', payload: { huilde: member.guild, member }}, { delay: 9999999999 })
Favna
Favna4mo ago
Readme is outdated I know But it's always better to check the type definitions first, even if you don't use typescript (if you use vscode it still has some basic checking with them)
SylveonDev
SylveonDevOP4mo ago
Ohhhh that explains a lot I shall see if this fixes my issue
Favna
Favna4mo ago
FYI If you want some basic QoL but still write JavaScript (as much as I would recommend typescript but you do you) you can create a tsconfig file and put this in, then you can continue to write JS but get notified of these kind of mistakes
{
"extends": [
"@sapphire/ts-config"
],
"compilerOptions": {
"incremental": false,
"noEmit": true,
"checkJs": true,
"allowJs": true,
},
"include": ["src"]
}
{
"extends": [
"@sapphire/ts-config"
],
"compilerOptions": {
"incremental": false,
"noEmit": true,
"checkJs": true,
"allowJs": true,
},
"include": ["src"]
}
(Assuming your files are in a directory called src at the bottom there) That'll nudge the vscode TSServer to do some checking while you write
SylveonDev
SylveonDevOP4mo ago
Eventually I will rewrite to typescript. I have been learning the basics to ts. The code is hosted on the root project directory, so would I change include to a .?
Favna
Favna4mo ago
Yes and add an exclude of node_modules
SylveonDev
SylveonDevOP4mo ago
Yep that worked, thanks.
Want results from more Discord servers?
Add your server