How to get name&description (default and localized)?

I know about container.stores.get('commands') , but I don't want to use decorators. Also, I want to get to the localized variants of the name&description. Any ideas how to do it except for adding i18n sapphire plugin or it's the only option?
8 Replies
Prosta4ok_ua
Prosta4ok_uaOP3w ago
<command>.options.description still doesn't work for command description not in the decorators
Favna
Favna3w ago
can you describe what exactly you want because it's not really clear to me what code you're struggling with right now which decorator for example?
Prosta4ok_ua
Prosta4ok_uaOP3w ago
For example, I have this command: (without any decorators)https://gist.github.com/Prosta4okua/317ab84bc669a695510966ba8c10bdf5 And I want to create command /help that prints all commands and their descriptions. I want to support two languages. I know how to get locale from user, I know how to set the localization of the application command. I need a way to receive names and descriptions (including in other localization). Basically something like this: [ {command: {name: 'google', nameLocalization: {'uk': ...}, description: 'Desc', descriptionLocalization: {'uk': 'Desc in uk'}'}, ...] I have this command:
import { Command } from '@sapphire/framework';
import { Locale } from 'discord.js';
import { container } from '@sapphire/framework';
import { ApplyOptions } from '@sapphire/decorators';

@ApplyOptions<Command.Options>({
description: 'Shows a list of available commands'
})
export class HelpCommand extends Command {
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand(
(builder) => {
return builder
.setName('help')
.setNameLocalization(Locale.Ukrainian, 'допомога')
.setDescription('Shows a list of available commands')
.setDescriptionLocalization(Locale.Ukrainian, 'Показує список доступних команд');
},
{ idHints: ['1335626733210042408'] }
);
}

public override async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
let resultText = '';
const result = container.stores.get('commands');
result.map((command) => {
resultText += `${command.name} - ${command.options.description} | ${command.category} | ${command.options}\n`;
});

return interaction.reply(resultText);
}
}
import { Command } from '@sapphire/framework';
import { Locale } from 'discord.js';
import { container } from '@sapphire/framework';
import { ApplyOptions } from '@sapphire/decorators';

@ApplyOptions<Command.Options>({
description: 'Shows a list of available commands'
})
export class HelpCommand extends Command {
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand(
(builder) => {
return builder
.setName('help')
.setNameLocalization(Locale.Ukrainian, 'допомога')
.setDescription('Shows a list of available commands')
.setDescriptionLocalization(Locale.Ukrainian, 'Показує список доступних команд');
},
{ idHints: ['1335626733210042408'] }
);
}

public override async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
let resultText = '';
const result = container.stores.get('commands');
result.map((command) => {
resultText += `${command.name} - ${command.options.description} | ${command.category} | ${command.options}\n`;
});

return interaction.reply(resultText);
}
}
Favna
Favna3w ago
it's part of the plugin other than that setNameLocalization takes an object so if you dont want to use the plugin and just provide the strings in code just use an object
Favna
Favna3w ago
discord.js
discord.js
discord.js is a powerful Node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
Prosta4ok_ua
Prosta4ok_uaOP3w ago
both, that's why it worked without object
No description
Prosta4ok_ua
Prosta4ok_uaOP3w ago
Thanks, appreciate it!

Did you find this page helpful?