locale

anyone having issues getting locale from users when initiating a command? i added all the logs, seems no mater what, or the intents, Won't let me see the locale for use with i18n

const { SlashCommandBuilder } = require("discord.js"); const i18n = require('../i18n.cjs'); module.exports = { data: new SlashCommandBuilder() .setName('ping') .setDescription(i18n.__('ping.description')), async execute(interaction) { try { const userLocale = interaction.user.locale || 'en'; console.log(User's Discord locale: ${userLocale}); // Logging the detected locale i18n.setLocale(userLocale); console.log(i18n locale after setting: ${i18n.getLocale()}); // Logging the set locale in i18n // Time the interaction was created const sentAt = interaction.createdTimestamp; // Reply to the interaction const reply = await interaction.reply({ content: 'Pinging...', fetchReply: true }); // Time the reply was created const repliedAt = reply.createdTimestamp; // Calculate the latency const latency = repliedAt - sentAt; // Edit the reply to show the latency using translation await interaction.editReply(i18n.__('ping.response', { latency: ${latency} })); } catch (err) { console.error(err); await interaction.editReply({content: "Something went wrong"}); } }, };
Was this page helpful?