manual task compiler error

The heading might not be the best here but I tried searching and the docs but can't figure out what I am doing wrong. I used the scheduled tasks plugin. I've been using it for a while and my bot runs certain pattern tasks with no issue. I want to create a manual task that deletes a message if it's deletable after a set period of time. I followed the directions here https://github.com/sapphiredev/plugins/blob/1f0ca075501324013b7a79410ee4bc04ebad9720/packages/scheduled-tasks/README.md#manual-task-example My compiler is giving this error: Expected 1-2 arguments, but got 3.ts(2554)
GitHub
plugins/packages/scheduled-tasks/README.md at 1f0ca075501324013b7a7...
Plugins for the Sapphire Framework. Contribute to sapphiredev/plugins development by creating an account on GitHub.
Solution:
something like this:
this.container.tasks.create({ name: 'delete-message', payload: { message } }, { delay: offset })
this.container.tasks.create({ name: 'delete-message', payload: { message } }, { delay: offset })
...
Jump to solution
7 Replies
WhacK
WhacKOP4mo ago
// where the task is called
if (xpGain === 0) {
// TODO - fix manual task creation
const offset = this.container.prod ? Time.Minute * 30 : Time.Minute;
this.container.tasks.create('delete-message', { payload: message }, offset);
}
// where the task is called
if (xpGain === 0) {
// TODO - fix manual task creation
const offset = this.container.prod ? Time.Minute * 30 : Time.Minute;
this.container.tasks.create('delete-message', { payload: message }, offset);
}
import { ScheduledTask } from '@sapphire/plugin-scheduled-tasks';
import { ApplyOptions } from '@sapphire/decorators';
import { Message } from 'discord.js';
import { isNullishOrEmpty } from '@sapphire/utilities';

@ApplyOptions<ScheduledTask.Options>({
name: 'delete-message',
customJobOptions: {
removeOnComplete: true
}
})
export class DeleteMessageTask extends ScheduledTask {
protected async cleanupMessage(message: Message<boolean>) {
try {
if (message && message.deletable) {
const deleted = await message.delete().catch(() => []);
return isNullishOrEmpty(deleted) ? Promise.reject('Unable to delete message.') : Promise.resolve();
}
throw new Error('Message cannot be deleted.');
} catch (error) {
const message = error.message ?? 'Unknown error occurred cleaning up message.';
this.container.logger.debug(message, error);
return Promise.reject(message);
}
}

protected isMessage(payload: unknown): payload is Message<boolean> {
if (typeof payload !== 'object' || payload === null) {
return false;
}
const msg = payload as Message<boolean>;
return typeof msg.id === 'string' && typeof msg.content === 'string' && typeof msg.author === 'object';
}

public async run(payload: unknown) {
if (this.isMessage(payload)) return await this.cleanupMessage(payload);

return;
}
}
import { ScheduledTask } from '@sapphire/plugin-scheduled-tasks';
import { ApplyOptions } from '@sapphire/decorators';
import { Message } from 'discord.js';
import { isNullishOrEmpty } from '@sapphire/utilities';

@ApplyOptions<ScheduledTask.Options>({
name: 'delete-message',
customJobOptions: {
removeOnComplete: true
}
})
export class DeleteMessageTask extends ScheduledTask {
protected async cleanupMessage(message: Message<boolean>) {
try {
if (message && message.deletable) {
const deleted = await message.delete().catch(() => []);
return isNullishOrEmpty(deleted) ? Promise.reject('Unable to delete message.') : Promise.resolve();
}
throw new Error('Message cannot be deleted.');
} catch (error) {
const message = error.message ?? 'Unknown error occurred cleaning up message.';
this.container.logger.debug(message, error);
return Promise.reject(message);
}
}

protected isMessage(payload: unknown): payload is Message<boolean> {
if (typeof payload !== 'object' || payload === null) {
return false;
}
const msg = payload as Message<boolean>;
return typeof msg.id === 'string' && typeof msg.content === 'string' && typeof msg.author === 'object';
}

public async run(payload: unknown) {
if (this.isMessage(payload)) return await this.cleanupMessage(payload);

return;
}
}
{
"name": "beholder",
"version": "8.3.0",
"description": "A bot used to manage and interact with the D&D 5e Discord Server Engrimoore.",
"author": "Engrimoore Code Weavers",
"license": "Apache-2.0",
"main": "dist/beholder.js",
"private": true,
"type": "commonjs",
"engines":{
"node": "18.18.2",
"npm": "10.2.1"
},
"dependencies": {
"@sapphire/bitfield": "^1.2.2",
"@sapphire/decorators": "^6.1.0",
"@sapphire/discord-utilities": "^3.3.0",
"@sapphire/discord.js-utilities": "^7.2.1",
"@sapphire/eslint-config": "^5.0.4",
"@sapphire/eslint-plugin-result": "^2.0.3",
"@sapphire/fetch": "^3.0.2",
"@sapphire/framework": "5.2.1",
"@sapphire/lexure": "^1.1.7",
"@sapphire/pieces": "^4.2.2",
"@sapphire/plugin-api": "^6.1.1",
"@sapphire/plugin-editable-commands": "^4.0.2",
"@sapphire/plugin-i18next": "^7.1.2",
"@sapphire/plugin-logger": "^4.0.2",
"@sapphire/plugin-pattern-commands": "^6.0.2",
"@sapphire/plugin-scheduled-tasks": "^10.0.1",
"@sapphire/plugin-subcommands": "^6.0.3",
"@sapphire/result": "^2.6.6",
"@sapphire/shapeshift": "^4.0.0",
"@sapphire/snowflake": "^3.5.3",
"@sapphire/stopwatch": "^1.5.2",
"@sapphire/time-utilities": "^1.7.12",
"@sapphire/type": "^2.4.4",
"@sapphire/utilities": "^3.16.2",
"@skyra/env-utilities": "^1.3.0",
"colorette": "^2.0.20",
"discord.js": "^14.15.2",
"dotenv-cra": "^3.0.3",
"reflect-metadata": "^0.2.2",
"ws": "^8.17.0"
},
"devDependencies": {
"@sapphire/prettier-config": "^2.0.0",
"@sapphire/ts-config": "^5.0.0",
"@types/node": "^20.11.5",
"@types/ws": "^8.5.10",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.4",
"tsc-watch": "^6.0.4",
"typescript": "^5.3.3"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"start": "node dist/beholder.js",
"dev": "run-s build start",
"prod:test": "NODE_ENV=production node dist/beholder.js",
"watch:start": "tsc-watch --onSuccess \"node ./dist/beholder.js\"",
"format": "prettier --write \"src/**/*.ts\""
},
"prettier": "@sapphire/prettier-config"
}
{
"name": "beholder",
"version": "8.3.0",
"description": "A bot used to manage and interact with the D&D 5e Discord Server Engrimoore.",
"author": "Engrimoore Code Weavers",
"license": "Apache-2.0",
"main": "dist/beholder.js",
"private": true,
"type": "commonjs",
"engines":{
"node": "18.18.2",
"npm": "10.2.1"
},
"dependencies": {
"@sapphire/bitfield": "^1.2.2",
"@sapphire/decorators": "^6.1.0",
"@sapphire/discord-utilities": "^3.3.0",
"@sapphire/discord.js-utilities": "^7.2.1",
"@sapphire/eslint-config": "^5.0.4",
"@sapphire/eslint-plugin-result": "^2.0.3",
"@sapphire/fetch": "^3.0.2",
"@sapphire/framework": "5.2.1",
"@sapphire/lexure": "^1.1.7",
"@sapphire/pieces": "^4.2.2",
"@sapphire/plugin-api": "^6.1.1",
"@sapphire/plugin-editable-commands": "^4.0.2",
"@sapphire/plugin-i18next": "^7.1.2",
"@sapphire/plugin-logger": "^4.0.2",
"@sapphire/plugin-pattern-commands": "^6.0.2",
"@sapphire/plugin-scheduled-tasks": "^10.0.1",
"@sapphire/plugin-subcommands": "^6.0.3",
"@sapphire/result": "^2.6.6",
"@sapphire/shapeshift": "^4.0.0",
"@sapphire/snowflake": "^3.5.3",
"@sapphire/stopwatch": "^1.5.2",
"@sapphire/time-utilities": "^1.7.12",
"@sapphire/type": "^2.4.4",
"@sapphire/utilities": "^3.16.2",
"@skyra/env-utilities": "^1.3.0",
"colorette": "^2.0.20",
"discord.js": "^14.15.2",
"dotenv-cra": "^3.0.3",
"reflect-metadata": "^0.2.2",
"ws": "^8.17.0"
},
"devDependencies": {
"@sapphire/prettier-config": "^2.0.0",
"@sapphire/ts-config": "^5.0.0",
"@types/node": "^20.11.5",
"@types/ws": "^8.5.10",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.4",
"tsc-watch": "^6.0.4",
"typescript": "^5.3.3"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"start": "node dist/beholder.js",
"dev": "run-s build start",
"prod:test": "NODE_ENV=production node dist/beholder.js",
"watch:start": "tsc-watch --onSuccess \"node ./dist/beholder.js\"",
"format": "prettier --write \"src/**/*.ts\""
},
"prettier": "@sapphire/prettier-config"
}
Favna
Favna4mo ago
It's entirely possible that the readme isn't up-to-date. Other than the error TS also lets you go the symbol that you're calling (ctrl+click or right click and go to reference) and it'll open the .d.ts file and you can view the ptoper usage and adjust accordingly.
WhacK
WhacKOP4mo ago
ok thank you I'll try that
/**
* Creates a scheduled task.
*
* @param task - The task to be scheduled.
* @param payload - The payload for the task.
* @param options - The options for the task.
*/
create<T extends ScheduledTasksResolvable>(task: T, //
options?: ScheduledTasksTaskOptions | number): Promise<ScheduledTasksJob<T>>;
/**
* Creates a scheduled task.
*
* @param task - The task to be scheduled.
* @param payload - The payload for the task.
* @param options - The options for the task.
*/
create<T extends ScheduledTasksResolvable>(task: T, //
options?: ScheduledTasksTaskOptions | number): Promise<ScheduledTasksJob<T>>;
this looks like it only takes the options or a number (delay I assume). I see the change now though it's in the comments below and is done through module declaration
* declare module '@sapphire/plugin-scheduled-tasks' {
* interface ScheduledTasks {
* // A task named `Mute` which requires no payload:
* Mute: never;
*
* // A task named `Unmute` which requires a payload with a `userId` property:
* Unmute: {
* userId: string;
* };
*
* // A task named `Ban` which has a payload with an optional `moderatorId` property:
* LogAction: {
* moderatorId?: string;
* };
* }
* }
*
* declare module '@sapphire/plugin-scheduled-tasks' {
* interface ScheduledTasks {
* // A task named `Mute` which requires no payload:
* Mute: never;
*
* // A task named `Unmute` which requires a payload with a `userId` property:
* Unmute: {
* userId: string;
* };
*
* // A task named `Ban` which has a payload with an optional `moderatorId` property:
* LogAction: {
* moderatorId?: string;
* };
* }
* }
*
I updated to this but it still doesn’t allow you to provide the payload. I just skipped the task and use TimerManager.setTimeout to do it without
FC
FC4mo ago
Yeah, it seems the readme isn't updated. You have to provide the payload with the task name in the first argument https://github.com/sapphiredev/plugins/blob/d6024cd53f8f1d085788dcc7037c72add8a9291c/packages/scheduled-tasks/src/lib/ScheduledTaskHandler.ts#L88
Solution
FC
FC4mo ago
something like this:
this.container.tasks.create({ name: 'delete-message', payload: { message } }, { delay: offset })
this.container.tasks.create({ name: 'delete-message', payload: { message } }, { delay: offset })
WhacK
WhacKOP4mo ago
I’ve been swamped at work but will try this thanks
WhacK
WhacKOP4mo ago
That was it thanks again
Want results from more Discord servers?
Add your server