Trying to set `/language` command that completely changes language of a bot but app is not respondin

const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const fs = require('fs');
const restartBot = require('../../utils/restart-bot');
const { language } = require('../../config.json'); // Fetch language key from config.json
const languageSetting = require(`../../resources/languages/${language}.json`) ; // Fetch language based text responses

module.exports = {
data: new SlashCommandBuilder()
.setName(`${languageSetting.language_name}`)
.setDescription(`${languageSetting.language_desc}`)
.addStringOption(option =>
option.setName('choose_language')
.setDescription(`${languageSetting.language_optdesc}`)
.setRequired(true)
.addChoices(
{ name: 'English', value: 'eng' },
{ name: 'Polski', value: 'pl' }
)
),
category: 'admin',
async execute(interaction) {

const interactionUserPermissions = interaction.member.permissions;

if(interactionUserPermissions.has(PermissionFlagsBits.Administrator) || interactionUserPermissions.has(PermissionFlagsBits.ManageGuild) || interaction.member.id == process.env.BOT_DEVELOPER){
// Get the chosen language from the interaction
const chosenLanguage = interaction.options.getString('choose_language');

// Read the current configuration from the file
const configPath = './config.json';
const rawConfig = fs.readFileSync(configPath);
const config = JSON.parse(rawConfig);

// Update the language key with the chosen language
config.language = chosenLanguage;

// Write the updated configuration back to the file
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));

if(chosenLanguage == "pl"){}
// Respond to the user indicating that the language has been changed
await interaction.reply(`${languageSetting.language_success} ${chosenLanguage}`);
restartBot.restartBot();
} else{
interaction.reply({content: `${languageSetting.error_permissionsNeeded}`, ephemeral: true})
}
},
};
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const fs = require('fs');
const restartBot = require('../../utils/restart-bot');
const { language } = require('../../config.json'); // Fetch language key from config.json
const languageSetting = require(`../../resources/languages/${language}.json`) ; // Fetch language based text responses

module.exports = {
data: new SlashCommandBuilder()
.setName(`${languageSetting.language_name}`)
.setDescription(`${languageSetting.language_desc}`)
.addStringOption(option =>
option.setName('choose_language')
.setDescription(`${languageSetting.language_optdesc}`)
.setRequired(true)
.addChoices(
{ name: 'English', value: 'eng' },
{ name: 'Polski', value: 'pl' }
)
),
category: 'admin',
async execute(interaction) {

const interactionUserPermissions = interaction.member.permissions;

if(interactionUserPermissions.has(PermissionFlagsBits.Administrator) || interactionUserPermissions.has(PermissionFlagsBits.ManageGuild) || interaction.member.id == process.env.BOT_DEVELOPER){
// Get the chosen language from the interaction
const chosenLanguage = interaction.options.getString('choose_language');

// Read the current configuration from the file
const configPath = './config.json';
const rawConfig = fs.readFileSync(configPath);
const config = JSON.parse(rawConfig);

// Update the language key with the chosen language
config.language = chosenLanguage;

// Write the updated configuration back to the file
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));

if(chosenLanguage == "pl"){}
// Respond to the user indicating that the language has been changed
await interaction.reply(`${languageSetting.language_success} ${chosenLanguage}`);
restartBot.restartBot();
} else{
interaction.reply({content: `${languageSetting.error_permissionsNeeded}`, ephemeral: true})
}
},
};
2 Replies
d.js toolkit
d.js toolkit12mo 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
Not Kuma anymore
Not Kuma anymoreOP12mo ago
It looks like it doesnt even reach the main part of the code. Just doesn't want to respond Is something like that even possible? Thanks a lot 1heartcute
Want results from more Discord servers?
Add your server