jake2482
jake2482
DIAdiscord.js - Imagine an app
Created by jake2482 on 8/3/2023 in #djs-questions
threads, forums. parent ID
I might have glossed over where this is. Trying to make a event listener that can see the channel ID of the parent thread or forum.
let channelId = msg.channel.type === 'GUILD_PUBLIC_THREAD' || msg.channel.type === 'GUILD_PRIVATE_THREAD'
? msg.channel.parentId
: msg.channel.id;
let channelId = msg.channel.type === 'GUILD_PUBLIC_THREAD' || msg.channel.type === 'GUILD_PRIVATE_THREAD'
? msg.channel.parentId
: msg.channel.id;
4 replies
DIAdiscord.js - Imagine an app
Created by jake2482 on 7/27/2023 in #djs-questions
locales in interactions?
so i have a command that handles locales, it has buttons and those are handled in a different event handling file. but I cannot figure out how to extract locale from interactions.
client.on(Events.InteractionCreate, async interaction => {
let userLocale = interaction.member ? interaction.member.locale : (interaction.user.locale || 'en');

console.log('User's Discord Locale: ${userLocale}');

// code

// Set the locale for i18n
i18n.setLocale(userLocale);
console.log('bot.js Current i18n locale: ${i18n.getLocale()}');
});
client.on(Events.InteractionCreate, async interaction => {
let userLocale = interaction.member ? interaction.member.locale : (interaction.user.locale || 'en');

console.log('User's Discord Locale: ${userLocale}');

// code

// Set the locale for i18n
i18n.setLocale(userLocale);
console.log('bot.js Current i18n locale: ${i18n.getLocale()}');
});
Prior to that initial let, i had: let userLocale = interaction.user.locale || 'en'; which also didn't achieve the results either
3 replies
DIAdiscord.js - Imagine an app
Created by jake2482 on 7/25/2023 in #djs-questions
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"}); } }, };
6 replies