Saltearse al contenido

Extendiendo CommandContext

Es posible que te hayas encontrado en una situación en la que deseas recibir datos personalizados dentro del CommandContext de Seyfert.

Para lograrlo, simplemente configura la opción context al definir el cliente de Seyfert. En esta opción, necesitas usar una función llamada extendContext, donde puedes manejar la interacción o mensaje de tu comando y devolver los datos personalizados que quieres agregar al contexto. Por ejemplo:

import {
class Client<Ready extends boolean = boolean>
Client
,
function extendContext<T extends {}>(cb: (interaction: Parameters<NonNullable<BaseClientOptions["context"]>>[0]) => T): (interaction: Parameters<NonNullable<BaseClientOptions["context"]>>[0]) => T

Extends the context of a command interaction.

@paramcb - The callback function to extend the context.

@returnsThe extended context.

@example const customContext = extendContext((interaction) => { return { owner: '123456789012345678', // Add your custom properties here }; });

extendContext
} from 'seyfert';
const
const context: (interaction: Parameters<NonNullable<BaseClientOptions["context"]>>[0]) => {
myCoolProp: string;
}
context
=
extendContext<{
myCoolProp: string;
}>(cb: (interaction: Parameters<NonNullable<BaseClientOptions["context"]>>[0]) => {
myCoolProp: string;
}): (interaction: Parameters<NonNullable<BaseClientOptions["context"]>>[0]) => {
myCoolProp: string;
}

Extends the context of a command interaction.

@paramcb - The callback function to extend the context.

@returnsThe extended context.

@example const customContext = extendContext((interaction) => { return { owner: '123456789012345678', // Add your custom properties here }; });

extendContext
((
interaction: ChatInputCommandInteraction<boolean> | UserCommandInteraction<boolean> | MessageCommandInteraction<boolean> | ComponentInteraction<...> | ModalSubmitInteraction<...> | EntryPointInteraction<...>
interaction
) => {
// Aquí puedes añadir
return {
myCoolProp: string
myCoolProp
: 'seyfert>>'
};
});
const
const client: Client<boolean>
client
= new
new Client<boolean>(options?: ClientOptions): Client<boolean>
Client
({
BaseClientOptions.context?: (interaction: ChatInputCommandInteraction<boolean> | UserCommandInteraction<boolean> | MessageCommandInteraction<boolean> | ComponentInteraction | ModalSubmitInteraction | EntryPointInteraction<boolean> | When<InferWithPrefix, MessageStructure, never>) => Record<string, unknown>
context
});

Aunque hayas extendido el contexto, las propiedades que has añadido no están tipadas en el CommandContext. Para tiparlas, tendrás que declarar el módulo de Seyfert. Consulta la guía de declaración de módulos para más información.