Manual task not executing

Hiya, One of the tasks for a temp ban doesn't seem to execute after the amount of time I specified in the command. I've played around with other tasks that have worked before and still do work, updated the modules that are related to this and also delete the redis database after. I've also looked around and I don't think it's related to this: https://discord.com/channels/737141877803057244/1074660009117499413 because other pattern tasks have been working for a while, and I've gotten other called tasks to execute after 9 seconds. Versions of the modules: @sapphire/framework: 4.1.0 @sapphire/plugin-scheduled-tasks: 6.0.0 bullmq: 3.6.6 I'm also not using any modules that are currently in any betas/alphas. Snippets of the code: Snippet of the code in the application command: I am also using Duration from @sapphire/time-utilities for the variable time.
this.container.tasks.create('tempBan', {
userId: user.id,
guildId: guild.id,
}, time.offset);
this.container.logger.debug(`Temp Ban: ban time ${time.offset}`);
this.container.tasks.create('tempBan', {
userId: user.id,
guildId: guild.id,
}, time.offset);
this.container.logger.debug(`Temp Ban: ban time ${time.offset}`);
This command also works, it does ban the user and sends a log in a channel. Scheduled Task:
import { ScheduledTask } from '@sapphire/plugin-scheduled-tasks';

export class TempBan extends ScheduledTask {
public constructor(context: ScheduledTask.Context, options: ScheduledTask.Options) {
super(context, options);
}

public async run(payload: { userId: string, guildId: string }) {
this.container.logger.debug('Temp Unban Task: Currently running unban');
// More code, removed it just to not clog up the thread
}
}

declare module '@sapphire/plugin-scheduled-tasks' {
interface ScheduledTasks {
tempBan: never;
}
}
import { ScheduledTask } from '@sapphire/plugin-scheduled-tasks';

export class TempBan extends ScheduledTask {
public constructor(context: ScheduledTask.Context, options: ScheduledTask.Options) {
super(context, options);
}

public async run(payload: { userId: string, guildId: string }) {
this.container.logger.debug('Temp Unban Task: Currently running unban');
// More code, removed it just to not clog up the thread
}
}

declare module '@sapphire/plugin-scheduled-tasks' {
interface ScheduledTasks {
tempBan: never;
}
}
This is the only log I got in the console:
2023-02-16 17:55:38 - DEBUG - Temp Ban: ban time 30000
2023-02-16 17:55:38 - DEBUG - Temp Ban: ban time 30000
I would be happy to provide the code for the entire git repo with commands that work, or make a git repo with snippets of the code only related to temp bans.
Solution:
I feel slightly silly with how simple of a problem/fix it was. I used event listeners to find out that tempBan was not found but the name of the file was tempban.ts, so it wouldn't run because the file name was all lowercase.
Jump to solution
5 Replies
Favna
Favna•2y ago
Can you start by implement event listeners for the events https://github.com/sapphiredev/plugins/blob/1f0ca075501324013b7a79410ee4bc04ebad9720/packages/scheduled-tasks/src/lib/types/ScheduledTaskEvents.ts#L11-L35 to confirm that the scheduled task is being ran correctly and such?
Solution
Anthony
Anthony•2y ago
I feel slightly silly with how simple of a problem/fix it was. I used event listeners to find out that tempBan was not found but the name of the file was tempban.ts, so it wouldn't run because the file name was all lowercase.
Anthony
Anthony•2y ago
I don't know if I just don't understand TypeScript that well or if the documentation was potentially misleading? But I thought the name would be retrieved from declare module '@sapphire/plugin-scheduled-tasks' { ... }, so I didn't think the file name would've been the issue 😭 But thank you so much for your help :)) Oh yeah, I forgot to mention this, one of the reasons I thought it didn't have much to do with the naming is that I didn't get an error like TS2345: Argument of type '"tempban"' is not assignable to parameter of type 'keyof ScheduledTasks'. because of the file name, which is also why I thought tasks were ran like I thought they were.
Favna
Favna•2y ago
File names are always leading for the names of the Pieces. Same goes for commands, listeners, etc. If you want to set a custom name that diverts from the file name you set it through the constructor options. This is addressed in plenty on our user guide. And by using module augmentation you can tell TS that you have a Piece called thisisaverynicepiecethattotallyexistsandisnotfake but that doesn't mean it'll actually exist at runtime.
Anthony
Anthony•2y ago
Ohhh that makes sense, thank you for explaining it to me :) And yeah my bad about the way I've read the documentation, I have a very strange way of learning which is usually skimming through documentation and going through trial and error... which is not the best imo, but I struggle to read slowly, and I think this is where my downfall is, even though I spent hours trying to debug it 😭 but I think it's also why I don't ask a lot of questions as it's usually down to me being silly for the reasons above haha
Want results from more Discord servers?
Add your server