Teixeira
Teixeira
Explore posts from servers
SIASapphire - Imagine a framework
Created by Teixeira on 11/21/2024 in #sapphire-support
Precondition not triggering "chatInputCommandDenied"
Oh man. Of course... what a rookie mistake! Thank you, this fixed it!
9 replies
SIASapphire - Imagine a framework
Created by Teixeira on 11/21/2024 in #sapphire-support
Precondition not triggering "chatInputCommandDenied"
And here's the setting of the precondition on the command: CMServerDefaults.ts
export class CMServerDefaultsCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, { ...options, preconditions: ['ValidAutocompletedObjectIdArguments'] });
}

(...)
export class CMServerDefaultsCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, { ...options, preconditions: ['ValidAutocompletedObjectIdArguments'] });
}

(...)
9 replies
SIASapphire - Imagine a framework
Created by Teixeira on 11/21/2024 in #sapphire-support
Precondition not triggering "chatInputCommandDenied"
I know for a fact that the precondition is firing & returning an error in my test, as I've added a breakpoint to the return this.error (...) statement
9 replies
SIASapphire - Imagine a framework
Created by Teixeira on 11/21/2024 in #sapphire-support
Precondition not triggering "chatInputCommandDenied"
However, my chatInputCommandDenied listener isn't firing: ChatInputCommandDenied.ts
import { ChatInputCommandDeniedPayload, Events, Listener, type UserError } from '@sapphire/framework';
import Utils from '../lib/Utils.js';
import { CustomEmbedType } from '../ui/embeds/CustomEmbed.js';

export class ChatInputCommandDeniedListener extends Listener<typeof Events.ChatInputCommandDenied> {
public constructor(context: Listener.LoaderContext, options: Listener.Options) {
super(context, {
...options,
event: 'chatInputCommandDenied'
});
}

public async run(error: UserError, payload: ChatInputCommandDeniedPayload) {
try {
if (!payload.interaction.deferred) await payload.interaction.deferReply({ ephemeral: true });

const reply = await payload.interaction.editReply({
embeds: [
(await this.container.ui.embeds.create(CustomEmbedType.Error)) //
.setDescription(error.message)
],
components: []
});

Utils.deleteAfterDelay(reply, payload.interaction.webhook);
} catch (reason) {
this.container.logger.error(reason);
}
}
}
import { ChatInputCommandDeniedPayload, Events, Listener, type UserError } from '@sapphire/framework';
import Utils from '../lib/Utils.js';
import { CustomEmbedType } from '../ui/embeds/CustomEmbed.js';

export class ChatInputCommandDeniedListener extends Listener<typeof Events.ChatInputCommandDenied> {
public constructor(context: Listener.LoaderContext, options: Listener.Options) {
super(context, {
...options,
event: 'chatInputCommandDenied'
});
}

public async run(error: UserError, payload: ChatInputCommandDeniedPayload) {
try {
if (!payload.interaction.deferred) await payload.interaction.deferReply({ ephemeral: true });

const reply = await payload.interaction.editReply({
embeds: [
(await this.container.ui.embeds.create(CustomEmbedType.Error)) //
.setDescription(error.message)
],
components: []
});

Utils.deleteAfterDelay(reply, payload.interaction.webhook);
} catch (reason) {
this.container.logger.error(reason);
}
}
}
9 replies
SIASapphire - Imagine a framework
Created by Teixeira on 11/21/2024 in #sapphire-support
Precondition not triggering "chatInputCommandDenied"
ValidAutocompletedObjectIdArguments.ts
import { Precondition } from '@sapphire/framework';
import { ChatInputCommandInteraction, inlineCode } from 'discord.js';
import { Types } from 'mongoose';
import { RealmAutocompleteInteractionHandler } from '../interaction-handlers/RealmAutocompleteInteractionHandler.js';
import ZoneModeAutocompleteInteractionHandler from '../interaction-handlers/ZoneModeAutocompleteInteractionHandler.js';
import { RaidAutocompleteInteractionHandler } from '../interaction-handlers/RaidAutocompleteInteractionHandler.js';

export class ValidAutocompletedObjectIdArgumentsPrecondition extends Precondition {
private _autocompletedObjectIdOptionNames: string[] = [
RealmAutocompleteInteractionHandler.optionName,
ZoneModeAutocompleteInteractionHandler.optionName,
RaidAutocompleteInteractionHandler.optionName
];

public constructor(context: Precondition.LoaderContext, options: Precondition.Options) {
super(context, {
...options
});
}

public override async chatInputRun(interaction: ChatInputCommandInteraction) {
interaction.options.data.forEach((option) => {
if (
this._autocompletedObjectIdOptionNames.includes(option.name) &&
option.value &&
typeof option.value === 'string' &&
!Types.ObjectId.isValid(option.value)
) {
return this.error({
message: `Invalid parameter value for ${inlineCode(option.name)}. Please select one of the autocompleted options.`
});
}

return;
});

return this.ok();
}
}

declare module '@sapphire/framework' {
interface Preconditions {
ValidAutocompletedObjectIdArguments: never;
}
}
import { Precondition } from '@sapphire/framework';
import { ChatInputCommandInteraction, inlineCode } from 'discord.js';
import { Types } from 'mongoose';
import { RealmAutocompleteInteractionHandler } from '../interaction-handlers/RealmAutocompleteInteractionHandler.js';
import ZoneModeAutocompleteInteractionHandler from '../interaction-handlers/ZoneModeAutocompleteInteractionHandler.js';
import { RaidAutocompleteInteractionHandler } from '../interaction-handlers/RaidAutocompleteInteractionHandler.js';

export class ValidAutocompletedObjectIdArgumentsPrecondition extends Precondition {
private _autocompletedObjectIdOptionNames: string[] = [
RealmAutocompleteInteractionHandler.optionName,
ZoneModeAutocompleteInteractionHandler.optionName,
RaidAutocompleteInteractionHandler.optionName
];

public constructor(context: Precondition.LoaderContext, options: Precondition.Options) {
super(context, {
...options
});
}

public override async chatInputRun(interaction: ChatInputCommandInteraction) {
interaction.options.data.forEach((option) => {
if (
this._autocompletedObjectIdOptionNames.includes(option.name) &&
option.value &&
typeof option.value === 'string' &&
!Types.ObjectId.isValid(option.value)
) {
return this.error({
message: `Invalid parameter value for ${inlineCode(option.name)}. Please select one of the autocompleted options.`
});
}

return;
});

return this.ok();
}
}

declare module '@sapphire/framework' {
interface Preconditions {
ValidAutocompletedObjectIdArguments: never;
}
}
9 replies
SIASapphire - Imagine a framework
Created by Teixeira on 11/20/2024 in #discordjs-support
Is there a way to make autocomplete options only accept a listed option - not "custom" inputs?
Thank you both
6 replies
SIASapphire - Imagine a framework
Created by Teixeira on 11/20/2024 in #discordjs-support
Is there a way to make autocomplete options only accept a listed option - not "custom" inputs?
I see, I was hoping there was an alternative to validating the input (which is what I've been doing - in my case each option's value is an object id related to a mongoDB document, so now I just make it check if the value is a valid ObjectId string)
6 replies
SIASapphire - Imagine a framework
Created by Teixeira on 10/22/2024 in #sapphire-support
How can I delay the loading of pieces?
Think I should be able to do it with this but wanted to sanity check I'm not stupidly overthinking this and there's a much easier way to do it 😅
13 replies
SIASapphire - Imagine a framework
Created by Teixeira on 10/22/2024 in #sapphire-support
How can I delay the loading of pieces?
I want to load the emojis based on their names, and since I'm then using these custom emojis on some of my pieces, I want to make sure they're loaded before I start receiving events/commands
13 replies
SIASapphire - Imagine a framework
Created by Teixeira on 10/22/2024 in #sapphire-support
How can I delay the loading of pieces?
By the way since I have you here... This is related to something I'm trying to do for emojis after setting up your package @favware/discord-application-emojis-manager. I followed up on the message from your private server "Favware", not sure if you've seen it
13 replies
SIASapphire - Imagine a framework
Created by Teixeira on 10/22/2024 in #sapphire-support
How can I delay the loading of pieces?
Awesome this is exactly what I'm looking for
13 replies
SIASapphire - Imagine a framework
Created by Teixeira on 6/2/2024 in #sapphire-support
Validation error in `SlashCommandBuilder.addSubcommand`
Full stack trace in case it helps and version info - @sapphire/[email protected] @sapphire/[email protected] [email protected]
21 replies
SIASapphire - Imagine a framework
Created by Teixeira on 6/2/2024 in #sapphire-support
Validation error in `SlashCommandBuilder.addSubcommand`
/**
* Adds a new subcommand to this command.
*
* @param input - A function that returns a subcommand builder or an already built builder
*/
addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): TypeAfterAddingSubcommands;
/**
* Adds a new subcommand to this command.
*
* @param input - A function that returns a subcommand builder or an already built builder
*/
addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): TypeAfterAddingSubcommands;
TS types say it should accept the instance directly so I assumed I could
21 replies
SIASapphire - Imagine a framework
Created by Teixeira on 6/2/2024 in #sapphire-support
Validation error in `SlashCommandBuilder.addSubcommand`
Yeah this is it... Why do TS types accept the respective builder instances though? By the way @Answer Overflow isn't working atm
21 replies
SIASapphire - Imagine a framework
Created by Teixeira on 3/14/2024 in #sapphire-support
Globally setting the guild in which to register commands by default
Thank you!
114 replies
SIASapphire - Imagine a framework
Created by Teixeira on 3/14/2024 in #sapphire-support
Globally setting the guild in which to register commands by default
After updating the package I'm getting a TS error:
node_modules/@sapphire/framework/dist/esm/index.d.mts:1:22 - error TS2307: Cannot find module 'src' or its corresponding type declarations.

1 import * as src from 'src';
node_modules/@sapphire/framework/dist/esm/index.d.mts:1:22 - error TS2307: Cannot find module 'src' or its corresponding type declarations.

1 import * as src from 'src';
I ran npm update @sapphire/framework
114 replies
SIASapphire - Imagine a framework
Created by Teixeira on 3/14/2024 in #sapphire-support
Globally setting the guild in which to register commands by default
One last thing, should I mark any of the messages here as the solution, to @Answer Overflow? Feels like I shouldn't but not sure
114 replies
SIASapphire - Imagine a framework
Created by Teixeira on 3/14/2024 in #sapphire-support
Globally setting the guild in which to register commands by default
Okay thank you both for the help!
114 replies
SIASapphire - Imagine a framework
Created by Teixeira on 3/14/2024 in #sapphire-support
Globally setting the guild in which to register commands by default
So I'll have to wait for the update to be pushed to sapphire and then I can npm update my version and should be good to go?
114 replies