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"}); } }, };
5 Replies
d.js toolkit
d.js toolkit2y ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers. - Issue solved? Press the button!
Syjalo
Syjalo2y ago
User object doesn't has locale. You can access it from an interaction
jake2482
jake2482OP2y ago
Yup, that was it. thank you. I'm assuming the only way to locale the description of a command is storing user's locale in a database? or am i missing some trick here
d.js docs
d.js docs2y ago
Suggestion for @jake2482:guide Slash Commands: Localizations read more
jake2482
jake2482OP2y ago
thank you

Did you find this page helpful?