fluffy
fluffy
Explore posts from servers
SIASapphire - Imagine a framework
Created by fluffy on 7/11/2024 in #sapphire-support
Cooldown filter precondition
Yeah i realised afterwards that it didn't work as intended. and the precondition didn't run 😦 I wanted to extend the cooldown precondition method because I'm not sure how to code the cooldown myself. So i thought to just add to the super method
9 replies
SIASapphire - Imagine a framework
Created by fluffy on 7/11/2024 in #sapphire-support
Cooldown filter precondition
Would it be something like this?
import { Precondition } from "@sapphire/framework";
import {
Subcommand,
SubcommandPreconditions,
} from "@sapphire/plugin-subcommands";
import type { ChatInputCommandInteraction } from "discord.js";

const allowedRole = "920834418459967548";

export class UserPrecondition extends SubcommandPreconditions.PluginSubcommandCooldown {
public constructor(
context: Precondition.LoaderContext,
options: Precondition.Options
) {
super(context, {
...options,
name: "CustomCooldown",
});
}

public override async chatInputRun(
interaction: ChatInputCommandInteraction,
subcommand: Subcommand,
context: SubcommandPreconditions.PluginSubcommandCooldownContext
) {
if (
interaction.inCachedGuild() &&
interaction.guild.roles.cache.get(allowedRole)
) {
return this.ok();
}
return super.chatInputRun(interaction, subcommand, context);
}
}

declare module "@sapphire/framework" {
interface Preconditions {
CustomCooldown: never;
}
}
import { Precondition } from "@sapphire/framework";
import {
Subcommand,
SubcommandPreconditions,
} from "@sapphire/plugin-subcommands";
import type { ChatInputCommandInteraction } from "discord.js";

const allowedRole = "920834418459967548";

export class UserPrecondition extends SubcommandPreconditions.PluginSubcommandCooldown {
public constructor(
context: Precondition.LoaderContext,
options: Precondition.Options
) {
super(context, {
...options,
name: "CustomCooldown",
});
}

public override async chatInputRun(
interaction: ChatInputCommandInteraction,
subcommand: Subcommand,
context: SubcommandPreconditions.PluginSubcommandCooldownContext
) {
if (
interaction.inCachedGuild() &&
interaction.guild.roles.cache.get(allowedRole)
) {
return this.ok();
}
return super.chatInputRun(interaction, subcommand, context);
}
}

declare module "@sapphire/framework" {
interface Preconditions {
CustomCooldown: never;
}
}
9 replies
SIASapphire - Imagine a framework
Created by fluffy on 1/18/2023 in #sapphire-support
Subcommand unintentionally triggers Events.MessageCommandRun
Thank you for the default tip, even though jt still triggers the MessageRun event it is a sufficient workaround!
7 replies
SIASapphire - Imagine a framework
Created by fluffy on 1/18/2023 in #sapphire-support
Subcommand unintentionally triggers Events.MessageCommandRun
ah, my bot actually doesn't use message commands, I have / prefix purely to remind users how to use slash commands properly should they wrongly send the command as a message. There are way too many of them!
7 replies