Teixeira
Teixeira
Explore posts from servers
TtRPC
Created by Teixeira on 1/16/2025 in #❓-help
Route not found when using Fastify adapter
I'm currently running into the following error when attempting to issue a request to my server which is leveraging Fastify:
[19:04:02.888] INFO (57024): Route POST:/associateSocialMediaAccount not found
reqId: "req-1"
[19:04:02.892] INFO (57024): request completed
reqId: "req-1"
res: {
"statusCode": 404
}
responseTime: 5.059000000357628
[19:04:02.888] INFO (57024): Route POST:/associateSocialMediaAccount not found
reqId: "req-1"
[19:04:02.892] INFO (57024): request completed
reqId: "req-1"
res: {
"statusCode": 404
}
responseTime: 5.059000000357628
I'm instantiating the server as such:
const fastifyServer = fastify({
logger: true,
maxParamLength: 5000
});

fastifyServer.register(fastifyTRPCPlugin, {
prefix: '/trpc',
trpcOptions: {
router: appRouter,
createContext,
onError({ path, error }) {
logger.error(`Error in tRPC handler on path '${path}':`, error);
}
} satisfies FastifyTRPCPluginOptions<AppRouter>['trpcOptions']
});

try {
await fastifyServer.listen({
port: environment.API_PORT,
host: environment.isDev ? 'localhost' : '0.0.0.0'
});
} catch (reason: unknown) {
logger.error(reason);
}
const fastifyServer = fastify({
logger: true,
maxParamLength: 5000
});

fastifyServer.register(fastifyTRPCPlugin, {
prefix: '/trpc',
trpcOptions: {
router: appRouter,
createContext,
onError({ path, error }) {
logger.error(`Error in tRPC handler on path '${path}':`, error);
}
} satisfies FastifyTRPCPluginOptions<AppRouter>['trpcOptions']
});

try {
await fastifyServer.listen({
port: environment.API_PORT,
host: environment.isDev ? 'localhost' : '0.0.0.0'
});
} catch (reason: unknown) {
logger.error(reason);
}
appRouter looks like this:
(...)
import associateSocialMediaAccount from './procedures/associateSocialMediaAccount.js';

export const appRouter = router({
associateSocialMediaAccount
});
(...)
import associateSocialMediaAccount from './procedures/associateSocialMediaAccount.js';

export const appRouter = router({
associateSocialMediaAccount
});
associateSocialMediaAccount.ts:
export default publicProcedure
.input(socialMediaAccountSchema)
.mutation(async (opts) => {
// ...
});
export default publicProcedure
.input(socialMediaAccountSchema)
.mutation(async (opts) => {
// ...
});
I have triple checked that the client and server versions of tRPC match ( ^11.0.0-rc.700), I'm on "typescript": "^5.7.3" on both server and client, Node version v22.11.0
4 replies
DIAdiscord.js - Imagine an app
Created by Teixeira on 1/13/2025 in #djs-questions
`ModalBuilder` validation error
When creating a modal like this:
export default class InputSocialMediaAccountName extends CustomModal {
public override async build() {
this.setCustomId(PresetModal.InputSocialMediaAccountName)
.setTitle('Some title')
.setComponents([
new ActionRowBuilder<TextInputBuilder>() //
.setComponents([
new TextInputBuilder()
.setCustomId('handle')
.setLabel('Something')
.setMinLength(1)
.setPlaceholder('test')
.setRequired(true)
.setStyle(TextInputStyle.Short)
])
]);
}
}
export default class InputSocialMediaAccountName extends CustomModal {
public override async build() {
this.setCustomId(PresetModal.InputSocialMediaAccountName)
.setTitle('Some title')
.setComponents([
new ActionRowBuilder<TextInputBuilder>() //
.setComponents([
new TextInputBuilder()
.setCustomId('handle')
.setLabel('Something')
.setMinLength(1)
.setPlaceholder('test')
.setRequired(true)
.setStyle(TextInputStyle.Short)
])
]);
}
}
I'm running into this error: https://pastebin.com/S5fda8s4 Not sure what the issue could be as the validation error isn't really helpful (or I just don't know how to interpret it; CustomModal for reference
export default abstract class CustomModal extends ModalBuilder {
constructor(public readonly manager: ModalsManager) {
super();
}

public abstract build(): Promise<void>;
}
export default abstract class CustomModal extends ModalBuilder {
constructor(public readonly manager: ModalsManager) {
super();
}

public abstract build(): Promise<void>;
}
7 replies
SIASapphire - Imagine a framework
Created by Teixeira on 1/13/2025 in #discordjs-support
`ModalBuilder` validation error
When creating a modal like this:
export default class InputSocialMediaAccountName extends CustomModal {
public override async build() {
this.setCustomId(PresetModal.InputSocialMediaAccountName)
.setTitle('Connecting a social media account')
.setComponents([
new ActionRowBuilder<TextInputBuilder>() //
.setComponents([
new TextInputBuilder()
.setCustomId('handle')
.setLabel('Account Handle')
.setMinLength(1)
.setPlaceholder('@clipx')
.setRequired(true)
.setStyle(TextInputStyle.Short)
])
]);
}
}
export default class InputSocialMediaAccountName extends CustomModal {
public override async build() {
this.setCustomId(PresetModal.InputSocialMediaAccountName)
.setTitle('Connecting a social media account')
.setComponents([
new ActionRowBuilder<TextInputBuilder>() //
.setComponents([
new TextInputBuilder()
.setCustomId('handle')
.setLabel('Account Handle')
.setMinLength(1)
.setPlaceholder('@clipx')
.setRequired(true)
.setStyle(TextInputStyle.Short)
])
]);
}
}
I'm running into this error: https://pastebin.com/S5fda8s4 Not sure what the issue could be as the validation error isn't really helpful (or I just don't know how to interpret it; CustomModal for reference
export default abstract class CustomModal extends ModalBuilder {
constructor(public readonly manager: ModalsManager) {
super();
}

public abstract build(): Promise<void>;
}
export default abstract class CustomModal extends ModalBuilder {
constructor(public readonly manager: ModalsManager) {
super();
}

public abstract build(): Promise<void>;
}
3 replies
SIASapphire - Imagine a framework
Created by Teixeira on 12/30/2024 in #sapphire-support
`ApplicationCommandType` TypeError
I'm attempting to create a context menu command:
import { Command } from '@sapphire/framework';
import { ApplicationCommandType } from 'discord.js';

export class ListCharactersContextMenuCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, { ...options });
}

public override registerApplicationCommands(registry: Command.Registry) {
registry.registerContextMenuCommand(
(builder) =>
builder
.setName('List Characters') //
.setType(ApplicationCommandType.User)
);
}
}
import { Command } from '@sapphire/framework';
import { ApplicationCommandType } from 'discord.js';

export class ListCharactersContextMenuCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, { ...options });
}

public override registerApplicationCommands(registry: Command.Registry) {
registry.registerContextMenuCommand(
(builder) =>
builder
.setName('List Characters') //
.setType(ApplicationCommandType.User)
);
}
}
I'm getting the following TypeError:
Argument of type 'ApplicationCommandType.User' is not assignable to parameter of type 'ContextMenuCommandType'.ts(2345)
Argument of type 'ApplicationCommandType.User' is not assignable to parameter of type 'ContextMenuCommandType'.ts(2345)
I've tried importing the enum from discord-api-types/v10 instead but it throws the same error, not sure what I'm doing wrong!
9 replies
SIASapphire - Imagine a framework
Created by Teixeira on 11/21/2024 in #sapphire-support
Precondition not triggering "chatInputCommandDenied"
I have setup the following precondition:
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?
Title
7 replies
SIASapphire - Imagine a framework
Created by Teixeira on 10/22/2024 in #sapphire-support
How can I delay the loading of pieces?
Is there a way I can control when the pieces are loaded instead of having them loaded automatically on <SapphireClient>.login? I'd like to login to the client, then wait for the resolving of an async function, and then load the pieces in.
13 replies
SIASapphire - Imagine a framework
Created by Teixeira on 6/2/2024 in #sapphire-support
Validation error in `SlashCommandBuilder.addSubcommand`
No description
21 replies
SIASapphire - Imagine a framework
Created by Teixeira on 5/10/2024 in #discordjs-support
Keep getting "Shard 0 is reconnecting..." errors
No description
2 replies
SIASapphire - Imagine a framework
Created by Teixeira on 4/29/2024 in #discordjs-support
Is there a way to make the bot press a button component within a message
Wondering if there's a way to simulate a button press on a message (particularly a message that wasn't sent by the bot).
3 replies
SIASapphire - Imagine a framework
Created by Teixeira on 3/17/2024 in #sapphire-support
"ChatInputCommandError" listener not firing for subcommands
ChatInputCommandError.ts:
import { ChatInputCommandErrorPayload, Events, Listener } from '@sapphire/framework';
import generalErrorEmbed from '../lib/embed-presets/GeneralError.js';

/**
* Emitted after a chat input command runs unsuccesfully.
*/
export class ChatInputCommandErrorListener extends Listener<typeof Events.ChatInputCommandError> {
public constructor(context: Listener.LoaderContext, options: Listener.Options) {
super(context, {
...options,
event: 'chatInputCommandError'
});
}

/**
* Is called whenever an error is thrown in a `chatInputRun` method.
*
* @param error - The error thrown
* @param payload - The contextual payload
*/
public async run(error: unknown, payload: ChatInputCommandErrorPayload) {
(async () => {
if (!payload.interaction.deferred) await payload.interaction.deferReply({ ephemeral: true });

await payload.interaction.editReply({
embeds: [generalErrorEmbed]
});
})().catch(this.container.logger.error);

this.container.logger.error(`Encountered an error with the "chatInputRun" method of command "${payload.command.name}"`, error);
}
}
import { ChatInputCommandErrorPayload, Events, Listener } from '@sapphire/framework';
import generalErrorEmbed from '../lib/embed-presets/GeneralError.js';

/**
* Emitted after a chat input command runs unsuccesfully.
*/
export class ChatInputCommandErrorListener extends Listener<typeof Events.ChatInputCommandError> {
public constructor(context: Listener.LoaderContext, options: Listener.Options) {
super(context, {
...options,
event: 'chatInputCommandError'
});
}

/**
* Is called whenever an error is thrown in a `chatInputRun` method.
*
* @param error - The error thrown
* @param payload - The contextual payload
*/
public async run(error: unknown, payload: ChatInputCommandErrorPayload) {
(async () => {
if (!payload.interaction.deferred) await payload.interaction.deferReply({ ephemeral: true });

await payload.interaction.editReply({
embeds: [generalErrorEmbed]
});
})().catch(this.container.logger.error);

this.container.logger.error(`Encountered an error with the "chatInputRun" method of command "${payload.command.name}"`, error);
}
}
8 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
Even though I'm setting ApplicationCommandRegistries.setDefaultGuildIds(<GUILD_ID>); before <SapphireClient>.login the commands are still being registered globally. The commands do not have the guildIds option set.
114 replies
SIASapphire - Imagine a framework
Created by Teixeira on 1/24/2024 in #sapphire-support
NPM script stops working when tsconfig extends @sapphire/ts-config
My npm package has a simple build script:
"prebuild": "rimraf dist types",
"build": "tsc",
"prebuild": "rimraf dist types",
"build": "tsc",
When extending @sapphire/ts-config on my tsconfig.json , it stops working. Using typescript^5.3.2 and rimraf^5.0.5. Strangely enough, running tsc in the same working directory works as expected... Full tsconfig.json:
{
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict", "@sapphire/ts-config/decorators"],
"include": ["src"],
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "NodeNext",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": true,
"declarationDir": "types",
"sourceMap": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noFallthroughCasesInSwitch": true,
"strict": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"declarationMap": true,
"importHelpers": true
}
}
{
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict", "@sapphire/ts-config/decorators"],
"include": ["src"],
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "NodeNext",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": true,
"declarationDir": "types",
"sourceMap": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noFallthroughCasesInSwitch": true,
"strict": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"declarationMap": true,
"importHelpers": true
}
}
12 replies
SIASapphire - Imagine a framework
Created by Teixeira on 12/9/2023 in #sapphire-support
On Listeners
A couple questions on listener pieces: - Where can I find a list of available sapphire event identifiers and their respective arguments? - Does sapphire have any listeners or similar setup by default and if so which ones?
7 replies
SIASapphire - Imagine a framework
Created by Teixeira on 12/8/2023 in #sapphire-support
"Couldn't find a template file for that component type."
I'm having trouble setting up a custom component template using Sapphire CLI. Here's the template file (custom-listener.ts.sapphire):
{
"category": "listeners"
}
---
export class {{name}}Listener extends Listener {
public constructor(context: Listener.LoaderContext, options: Listener.Options) {
super(context, {
...options,
/**
* These two default to the file's name.
*/
name: 'ready',
event: 'ready'
/** */
});
}

/**
* Executes on event trigger
* @param client - The client that triggered this event
*/
public run(client: Client) {
// TODO
}
}
{
"category": "listeners"
}
---
export class {{name}}Listener extends Listener {
public constructor(context: Listener.LoaderContext, options: Listener.Options) {
super(context, {
...options,
/**
* These two default to the file's name.
*/
name: 'ready',
event: 'ready'
/** */
});
}

/**
* Executes on event trigger
* @param client - The client that triggered this event
*/
public run(client: Client) {
// TODO
}
}
When running npx sapphire generate custom-listener test it returns Couldn't find a template file for that component type. Default component templates work normally
4 replies
SIASapphire - Imagine a framework
Created by Teixeira on 8/17/2023 in #sapphire-support
Can I have multiple autocomplete interaction handlers?
When an autocomplete interaction comes through, if one of the autocomplete handlers returns this.none() in the parse method, will it still run the other handlers until it finds one that returns this.some()?
4 replies
SIASapphire - Imagine a framework
Created by Teixeira on 6/28/2023 in #sapphire-support
Setting autocomplete options based on other option's value
5 replies
DIAdiscord.js - Imagine an app
Created by Teixeira on 6/28/2023 in #djs-questions
Setting autocomplete options based on other option's value
11 replies
SIASapphire - Imagine a framework
Created by Teixeira on 6/28/2023 in #sapphire-support
autocompleteRun for sub commands
Is it possible to setup a autocompleteRun for specific subcommands similar to how it is done for chatInputRun?
6 replies