dazx
dazx
SIASapphire - Imagine a framework
Created by dazx on 5/14/2024 in #sapphire-support
messageRun commands
I'm getting an issue and honestly, don't know what's wrong, i'm using the template generated by the CLI and everything runs fine, however, when i try preconditions on messageRun subcommands they just not work for some reason? they work on messageRun commands but not subcommands. For example, i'm trying the precondition that comes with the template
export class OwnerOnlyPrecondition extends AllFlowsPrecondition {
#message = 'This command can only be used by the owner.';

public override chatInputRun(interaction: CommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override contextMenuRun(interaction: ContextMenuCommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override messageRun(message: Message) {
return this.doOwnerCheck(message.author.id);
}

private doOwnerCheck(userId: Snowflake) {
return OWNERS.includes(userId) ? this.ok() : this.error({ message: this.#message });
}
export class OwnerOnlyPrecondition extends AllFlowsPrecondition {
#message = 'This command can only be used by the owner.';

public override chatInputRun(interaction: CommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override contextMenuRun(interaction: ContextMenuCommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override messageRun(message: Message) {
return this.doOwnerCheck(message.author.id);
}

private doOwnerCheck(userId: Snowflake) {
return OWNERS.includes(userId) ? this.ok() : this.error({ message: this.#message });
}
it works on chatInput Subcommands and Commands, but not on messageRun subcommands
aliases: ['cws'],
description: 'A basic command with some subcommands',
subcommands: [
{
name: 'add',
messageRun: 'messageAdd',
preconditions: ['OwnerOnlyPrecondition']
},
aliases: ['cws'],
description: 'A basic command with some subcommands',
subcommands: [
{
name: 'add',
messageRun: 'messageAdd',
preconditions: ['OwnerOnlyPrecondition']
},
2024-05-14 02:03:34 - DEBUG - [0] - command-with-subcommands arestosora[249600415040012309] tests server[1134593541172117544]
2024-05-14 02:03:34 - DEBUG - [0] - command-with-subcommands arestosora[249600415040012309] tests server[1134593541172117544]
the command is fired but the precondition does not return anything and the command does not return anything either.
5 replies
SIASapphire - Imagine a framework
Created by dazx on 5/9/2024 in #sapphire-support
Scheduled Tasks not working
Hi, I've been trying to add the scheduled-tasks plugin but it doesn't seem to work, i honestly don't know what I'm doing wrong.
import { ScheduledTask } from '@sapphire/plugin-scheduled-tasks';

export class IntervalTask extends ScheduledTask {
public constructor(context: ScheduledTask.LoaderContext, options: ScheduledTask.Options) {
super(context, {
...options,
interval: 60_000 // 60 seconds
});
}

public async run() {
this.container.logger.info('I run every minute');
}
}

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

export class IntervalTask extends ScheduledTask {
public constructor(context: ScheduledTask.LoaderContext, options: ScheduledTask.Options) {
super(context, {
...options,
interval: 60_000 // 60 seconds
});
}

public async run() {
this.container.logger.info('I run every minute');
}
}

declare module '@sapphire/plugin-scheduled-tasks' {
interface ScheduledTasks {
interval: never;
}
}
I implemented this Success event but it's not logging anything
import { Listener } from '@sapphire/framework';
import { ScheduledTask, ScheduledTaskEvents, ScheduledTaskOptions } from '@sapphire/plugin-scheduled-tasks';

export class ScheduledTaskSuccessListener extends Listener<typeof ScheduledTaskEvents.ScheduledTaskSuccess> {
public constructor(context: Listener.LoaderContext, options: Listener.Options) {
super(context, {
event: ScheduledTaskEvents.ScheduledTaskSuccess,
once: false
});
}

public async run(task: ScheduledTask<"interval", ScheduledTaskOptions>): Promise<void> {
this.container.logger.info(`Scheduled task "${task}" completed successfully.`);
}
}
import { Listener } from '@sapphire/framework';
import { ScheduledTask, ScheduledTaskEvents, ScheduledTaskOptions } from '@sapphire/plugin-scheduled-tasks';

export class ScheduledTaskSuccessListener extends Listener<typeof ScheduledTaskEvents.ScheduledTaskSuccess> {
public constructor(context: Listener.LoaderContext, options: Listener.Options) {
super(context, {
event: ScheduledTaskEvents.ScheduledTaskSuccess,
once: false
});
}

public async run(task: ScheduledTask<"interval", ScheduledTaskOptions>): Promise<void> {
this.container.logger.info(`Scheduled task "${task}" completed successfully.`);
}
}
any help will be appreciated :)
10 replies