Cannot access localizations

I implemented the help command as follows, but I am having trouble getting Japanese from localizations Does anyone know the correct way to do this?
async execute(interaction) {
const { client } = interaction;
let commands = await client.application.commands.fetch();

if (interaction.guild) {
const guildCommands = await interaction.guild.commands.fetch();
commands = new Map([...commands, ...guildCommands]);
}

const userLocale = interaction.locale;
const isJapanese = userLocale === 'ja'; // Confirmed to be "true"

const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(isJapanese ? '利用可能なコマンド' : 'Available Commands')
.setDescription(isJapanese ? '以下は現在利用可能なコマンドのリストです' : 'Here is a list of currently available commands');

commands.forEach(command => {
if (command.name !== 'help') {
let description = command.description || (isJapanese ? '説明なし' : 'No description');
if (isJapanese && command?.descriptionLocalizations?.['ja']) { // Can't get through.
description = command.descriptionLocalizations['ja'];
}
embed.addFields({
name: `</${command.name}:${command.id}>`,
value: description,
inline: true
});
}
});
embed.setFooter({
text: isJapanese
? '注意: 一部のコマンドは特定のサーバーまたはユーザーインストールでのみ使用できます。'
: 'Note: Some commands may only be available in specific servers or user installations.'
});
await interaction.reply({ embeds: [embed], ephemeral: true });
},
};
async execute(interaction) {
const { client } = interaction;
let commands = await client.application.commands.fetch();

if (interaction.guild) {
const guildCommands = await interaction.guild.commands.fetch();
commands = new Map([...commands, ...guildCommands]);
}

const userLocale = interaction.locale;
const isJapanese = userLocale === 'ja'; // Confirmed to be "true"

const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(isJapanese ? '利用可能なコマンド' : 'Available Commands')
.setDescription(isJapanese ? '以下は現在利用可能なコマンドのリストです' : 'Here is a list of currently available commands');

commands.forEach(command => {
if (command.name !== 'help') {
let description = command.description || (isJapanese ? '説明なし' : 'No description');
if (isJapanese && command?.descriptionLocalizations?.['ja']) { // Can't get through.
description = command.descriptionLocalizations['ja'];
}
embed.addFields({
name: `</${command.name}:${command.id}>`,
value: description,
inline: true
});
}
});
embed.setFooter({
text: isJapanese
? '注意: 一部のコマンドは特定のサーバーまたはユーザーインストールでのみ使用できます。'
: 'Note: Some commands may only be available in specific servers or user installations.'
});
await interaction.reply({ embeds: [embed], ephemeral: true });
},
};
[example command]
module.exports = {
global: true,
data: new SlashCommandBuilder()
.setName('search')
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)
.setContexts(InteractionContextType.Guild, InteractionContextType.BotDM, InteractionContextType.PrivateChannel)
.setDescription('Searches for elements by the specified search character')
.setDescriptionLocalizations({
'ja': '指定した検索文字で要素を検索します'
})
...
module.exports = {
global: true,
data: new SlashCommandBuilder()
.setName('search')
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)
.setContexts(InteractionContextType.Guild, InteractionContextType.BotDM, InteractionContextType.PrivateChannel)
.setDescription('Searches for elements by the specified search character')
.setDescriptionLocalizations({
'ja': '指定した検索文字で要素を検索します'
})
...
Thanks for your help.
6 Replies
d.js toolkit
d.js toolkit3mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Ꮢ
OP3mo ago
In fact, it is displayed as shown in the image, and since the title, description, and footer are displayed in Japanese, it can be confirmed that isJapanese is true.
No description
d.js docs
d.js docs3mo ago
:property: ApplicationCommand#descriptionLocalizations @14.16.2 The description localizations for this command
Ꮢ
OP3mo ago
I did the following and the descriptionLocalizations was null. fetching but not accessible?
commands.forEach(command => {
if (command.name !== 'help') {
console.log('command: ', command);
commands.forEach(command => {
if (command.name !== 'help') {
console.log('command: ', command);
command: <ref *1> ApplicationCommand {
id: '1072261659718074368',
applicationId: '1072198324934938676',
guild: null,
guildId: null,
permissions: ApplicationCommandPermissionsManager {
manager: [Circular *1],
guild: null,
guildId: null,
commandId: '1072261659718074368'
},
type: 1,
nsfw: false,
name: 'search',
nameLocalizations: null,
nameLocalized: null,
description: 'Searches for elements by the specified search character',
descriptionLocalizations: null,
descriptionLocalized: null,
...
command: <ref *1> ApplicationCommand {
id: '1072261659718074368',
applicationId: '1072198324934938676',
guild: null,
guildId: null,
permissions: ApplicationCommandPermissionsManager {
manager: [Circular *1],
guild: null,
guildId: null,
commandId: '1072261659718074368'
},
type: 1,
nsfw: false,
name: 'search',
nameLocalizations: null,
nameLocalized: null,
description: 'Searches for elements by the specified search character',
descriptionLocalizations: null,
descriptionLocalized: null,
...
Syjalo
Syjalo3mo ago
Add withLocalizations: true option
Ꮢ
OP3mo ago
I didn't realize the additional options existed. Thank you for telling me, it worked fine :MinoriLove:
async execute(interaction) {
const { client } = interaction;
let commands = await client.application.commands.fetch({ withLocalizations: true });

if (interaction.guild) {
const guildCommands = await interaction.guild.commands.fetch({ withLocalizations: true });
commands = new Map([...commands, ...guildCommands]);
}
async execute(interaction) {
const { client } = interaction;
let commands = await client.application.commands.fetch({ withLocalizations: true });

if (interaction.guild) {
const guildCommands = await interaction.guild.commands.fetch({ withLocalizations: true });
commands = new Map([...commands, ...guildCommands]);
}
Want results from more Discord servers?
Add your server