log(n)
log(n)
Explore posts from servers
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
ah makes sense
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
😭
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
but -Denied emits errors for preconditions
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
so -Error emits errors for decorators
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
oh that's a mess
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
import { AllFlowsPrecondition } from "@sapphire/framework";
import { CommandInteraction, ContextMenuCommandInteraction, Message } from "discord.js";
import { env } from "../lib/validatedEnv.js";

export class OwnerOnlyPrecondition extends AllFlowsPrecondition {
public override async messageRun(message: Message) {
return this.checkOwner(message.author.id);
}

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

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

private async checkOwner(userId: string) {
return env.OWNER_ID === userId
? this.ok()
: this.error({ message: "Only the bot owner can use this command!" });
}
}

declare module "@sapphire/framework" {
interface Preconditions {
OwnerOnly: never;
}
}
import { AllFlowsPrecondition } from "@sapphire/framework";
import { CommandInteraction, ContextMenuCommandInteraction, Message } from "discord.js";
import { env } from "../lib/validatedEnv.js";

export class OwnerOnlyPrecondition extends AllFlowsPrecondition {
public override async messageRun(message: Message) {
return this.checkOwner(message.author.id);
}

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

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

private async checkOwner(userId: string) {
return env.OWNER_ID === userId
? this.ok()
: this.error({ message: "Only the bot owner can use this command!" });
}
}

declare module "@sapphire/framework" {
interface Preconditions {
OwnerOnly: never;
}
}
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
OwnerOnly for comparison
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
import { AllFlowsPrecondition } from "@sapphire/framework";
import { CommandInteraction, ContextMenuCommandInteraction, Message } from "discord.js";
import { env } from "../lib/validatedEnv.js";

export class MWAdminOnlyPrecondition extends AllFlowsPrecondition {
public override async messageRun(message: Message) {
return this.checkAdmin(message.author.id);
}

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

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

private async checkAdmin(userId: string) {
const member = await this.container.client.guilds.cache
.get(env.MAIN_GUILD_ID)!
.members.fetch(userId);

return member.roles.cache.has(env.ADMIN_ROLE_ID)
? this.ok()
: this.error({
message: "Only Midnight Wisteria administrators may use this command!",
});
}
}

declare module "@sapphire/framework" {
interface Preconditions {
MWAdminOnly: never;
}
}
import { AllFlowsPrecondition } from "@sapphire/framework";
import { CommandInteraction, ContextMenuCommandInteraction, Message } from "discord.js";
import { env } from "../lib/validatedEnv.js";

export class MWAdminOnlyPrecondition extends AllFlowsPrecondition {
public override async messageRun(message: Message) {
return this.checkAdmin(message.author.id);
}

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

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

private async checkAdmin(userId: string) {
const member = await this.container.client.guilds.cache
.get(env.MAIN_GUILD_ID)!
.members.fetch(userId);

return member.roles.cache.has(env.ADMIN_ROLE_ID)
? this.ok()
: this.error({
message: "Only Midnight Wisteria administrators may use this command!",
});
}
}

declare module "@sapphire/framework" {
interface Preconditions {
MWAdminOnly: never;
}
}
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
precondition
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
MWAdminOnly is the one behaving differently though, not OwnerOnly 🤔
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
@ApplyOptions<Subcommand.Options>({
name: "cc",
subcommands: [
{ name: "info", chatInputRun: "chatInputInfo" },
{ name: "register", chatInputRun: "chatInputRegister", preconditions: ["OwnerOnly"] },
{ name: "unregister", chatInputRun: "chatInputUnregister", preconditions: ["OwnerOnly"] },
{
name: "fix_permissions",
chatInputRun: "chatInputFixPermissions",
preconditions: ["OwnerOnly"],
},
{ name: "archive", chatInputRun: "chatInputArchive", preconditions: ["MWAdminOnly"] },
{ name: "unarchive", chatInputRun: "chatInputUnarchive", preconditions: ["MWAdminOnly"] },
{ name: "transfer", chatInputRun: "chatInputTransfer", preconditions: ["MWAdminOnly"] },
{ name: "create", chatInputRun: "chatInputCreate", preconditions: ["MWAdminOnly"] },
],
})
export class CustomChannelCommand extends Subcommand {
public override registerApplicationCommands(registry: ChatInputCommand.Registry) {
@ApplyOptions<Subcommand.Options>({
name: "cc",
subcommands: [
{ name: "info", chatInputRun: "chatInputInfo" },
{ name: "register", chatInputRun: "chatInputRegister", preconditions: ["OwnerOnly"] },
{ name: "unregister", chatInputRun: "chatInputUnregister", preconditions: ["OwnerOnly"] },
{
name: "fix_permissions",
chatInputRun: "chatInputFixPermissions",
preconditions: ["OwnerOnly"],
},
{ name: "archive", chatInputRun: "chatInputArchive", preconditions: ["MWAdminOnly"] },
{ name: "unarchive", chatInputRun: "chatInputUnarchive", preconditions: ["MWAdminOnly"] },
{ name: "transfer", chatInputRun: "chatInputTransfer", preconditions: ["MWAdminOnly"] },
{ name: "create", chatInputRun: "chatInputCreate", preconditions: ["MWAdminOnly"] },
],
})
export class CustomChannelCommand extends Subcommand {
public override registerApplicationCommands(registry: ChatInputCommand.Registry) {
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
and the command config
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
andi know for a fact the precondition returns an error, i checked that
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
import { ChatInputCommandDeniedPayload, Listener, UserError } from "@sapphire/framework";
import { ApplyOptions } from "@sapphire/decorators";
import { SubcommandPluginEvents } from "@sapphire/plugin-subcommands";

@ApplyOptions<Listener.Options>({
event: SubcommandPluginEvents.ChatInputSubcommandError,
})
export class ChatInputSubcommandError extends Listener<
typeof SubcommandPluginEvents.ChatInputSubcommandError
> {
public run(error: UserError, { interaction }: ChatInputCommandDeniedPayload) {
if (interaction.deferred || interaction.replied) {
return interaction.editReply({
content: error.message,
});
}

return interaction.reply({
content: error.message,
ephemeral: true,
});
}
}
import { ChatInputCommandDeniedPayload, Listener, UserError } from "@sapphire/framework";
import { ApplyOptions } from "@sapphire/decorators";
import { SubcommandPluginEvents } from "@sapphire/plugin-subcommands";

@ApplyOptions<Listener.Options>({
event: SubcommandPluginEvents.ChatInputSubcommandError,
})
export class ChatInputSubcommandError extends Listener<
typeof SubcommandPluginEvents.ChatInputSubcommandError
> {
public run(error: UserError, { interaction }: ChatInputCommandDeniedPayload) {
if (interaction.deferred || interaction.replied) {
return interaction.editReply({
content: error.message,
});
}

return interaction.reply({
content: error.message,
ephemeral: true,
});
}
}
30 replies
SIASapphire - Imagine a framework
Created by log(n) on 3/30/2024 in #sapphire-support
no error event on subcommand precondition
listener
30 replies