Daniel Passos
Daniel Passos
SIASapphire - Imagine a framework
Created by Daniel Passos on 12/21/2023 in #sapphire-support
error TS6053: File '@sapphire/ts-config' not found.
No description
4 replies
SIASapphire - Imagine a framework
Created by Daniel Passos on 12/7/2023 in #sapphire-support
Is that possible to have multiple routes in the same route class?
Something like:
@ApplyOptions<RouteOptions>({ route: 'users' })
export class UsersRoute extends Route {
// GET in /users
public async [methods.GET](request: ApiRequest, response: ApiResponse) {
// ...
return response.json(responseData);
}

// DELETE in /users/:userId
public async [methods.DELETE](request: ApiRequest, response: ApiResponse) {
//
return response.ok('...');
}
}
@ApplyOptions<RouteOptions>({ route: 'users' })
export class UsersRoute extends Route {
// GET in /users
public async [methods.GET](request: ApiRequest, response: ApiResponse) {
// ...
return response.json(responseData);
}

// DELETE in /users/:userId
public async [methods.DELETE](request: ApiRequest, response: ApiResponse) {
//
return response.ok('...');
}
}
4 replies
SIASapphire - Imagine a framework
Created by Daniel Passos on 12/5/2023 in #sapphire-support
Translate runIn error message
Since runIn pre condition do not return the identifier of precondition that failed, is there a way to translate the message of the error or should I just don't use the runIn: CommandOptionsRunTypeEnum.GuildAny and only use preconditions: ['GuildOnly']?
4 replies
SIASapphire - Imagine a framework
Created by Daniel Passos on 11/11/2023 in #sapphire-support
i18n based on the user locale
Is that possible to translate a message based on the user locale outside of the interaction command using resolveKey or something else??
4 replies
SIASapphire - Imagine a framework
Created by Daniel Passos on 10/29/2023 in #sapphire-support
Enable slash command for bot owners only
Is that possible for register a slash command to be visible only for a specific user like the bot owner?
5 replies
SIASapphire - Imagine a framework
Created by Daniel Passos on 5/11/2023 in #sapphire-support
Ignoring Precondition Failures
I'm working on a precondition that I wanna ignore on the ChatInputCommandDenied listener. The documentation suggests to a add information on the context in the Precondition
export class MyDummyPreconditions extends Precondition {
chatInputRun(
interaction: ChatInputCommandInteraction,
command: ChatInputCommand,
context: Precondition.Context
): Precondition.Result {
return this.error({ message: 'Ignored message', context: { silent: true } });
}
}
export class MyDummyPreconditions extends Precondition {
chatInputRun(
interaction: ChatInputCommandInteraction,
command: ChatInputCommand,
context: Precondition.Context
): Precondition.Result {
return this.error({ message: 'Ignored message', context: { silent: true } });
}
}
and check for it in ChatInputCommandDenied.
export class ChatInputCommandDeniedListener extends Listener<typeof Events.ChatInputCommandDenied> {
public async run({ context, message: content }: UserError, { interaction }: ChatInputCommandDeniedPayload) {
if (Reflect.get(Object(context), 'silent')) return;

if (interaction.deferred || interaction.replied) {
return interaction.editReply({
content,
allowedMentions: { users: [interaction.user.id], roles: [] }
});
}

return interaction.reply({
content,
allowedMentions: { users: [interaction.user.id], roles: [] },
ephemeral: true
});
}
}
export class ChatInputCommandDeniedListener extends Listener<typeof Events.ChatInputCommandDenied> {
public async run({ context, message: content }: UserError, { interaction }: ChatInputCommandDeniedPayload) {
if (Reflect.get(Object(context), 'silent')) return;

if (interaction.deferred || interaction.replied) {
return interaction.editReply({
content,
allowedMentions: { users: [interaction.user.id], roles: [] }
});
}

return interaction.reply({
content,
allowedMentions: { users: [interaction.user.id], roles: [] },
ephemeral: true
});
}
}
That works but I realized that the interaction response will be:
The application did not respond
Is that expected or did I miss something?
11 replies
SIASapphire - Imagine a framework
Created by Daniel Passos on 5/2/2023 in #sapphire-support
Accessing container inside of a decorator
Is that possible to have access to the container inside of a decorator. I'm trying to use it in a createFunctionPrecondition but I'm getting: TypeError: Cannot read properties of undefined (reading 'container')
5 replies
SIASapphire - Imagine a framework
Created by Daniel Passos on 4/30/2023 in #sapphire-support
Dynamic disable Slash Command based on role
Is that possible dynamic enable a slash command for a specify role in a specifically guild?
13 replies
SIASapphire - Imagine a framework
Created by Daniel Passos on 4/29/2023 in #sapphire-support
How to get the resolve a key without a target?
👋 Is there a way to access the locale strings using the i18next plugin passing the language instead of delegate it to the fetchLanguage? I'd love to have the nameLocalizations and descriptionLocalizations on my slash commands coming from the i18n json files. That will make it easy to collaborative translation. Something like:
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand({
name: this.name,
description: this.description,
descriptionLocalizations: {
'en-US': resolKey('en-US', 'ping:description')
'pt-BR': resolKey('pt-BR', 'ping:description')
}
});
}
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand({
name: this.name,
description: this.description,
descriptionLocalizations: {
'en-US': resolKey('en-US', 'ping:description')
'pt-BR': resolKey('pt-BR', 'ping:description')
}
});
}
Maybe something like resolKey('language', 'ping:success')
15 replies
SIASapphire - Imagine a framework
Created by Daniel Passos on 4/29/2023 in #sapphire-support
No auth data in the request after exchange the Discord code
👋 I'm fowling the built in Oauth2 route documentation but, every time that I fire a request after authenticate I have a null value in the request.auth on the backend side. Here is my frontend code for exchange the Discord code
const API_URL = 'http://127.0.0.1:4000';

export const authorize = (code: string) => axios.post<Authorize>(
`${API_URL}/oauth/callback`,
JSON.stringify({ code }),
{ withCredentials: true }
);
const API_URL = 'http://127.0.0.1:4000';

export const authorize = (code: string) => axios.post<Authorize>(
`${API_URL}/oauth/callback`,
JSON.stringify({ code }),
{ withCredentials: true }
);
and here is the Precondition I'm using on the bot/backend side:
export const authenticated = () =>
createFunctionPrecondition(
(request: ApiRequest) => {
const authenticated = Boolean(request.auth?.token);
logDebug((authenticated) ? EventType.SUCCESS : EventType.ERROR, 'authenticated', request.auth);
return authenticated;
},
(_request: ApiRequest, response: ApiResponse) => response.error(HttpCodes.Unauthorized)
);
export const authenticated = () =>
createFunctionPrecondition(
(request: ApiRequest) => {
const authenticated = Boolean(request.auth?.token);
logDebug((authenticated) ? EventType.SUCCESS : EventType.ERROR, 'authenticated', request.auth);
return authenticated;
},
(_request: ApiRequest, response: ApiResponse) => response.error(HttpCodes.Unauthorized)
);
PS: The Discord code was success exchange and I received the LoginData back in the front end.
51 replies