Nova Aurelia Knight
Nova Aurelia Knight
DIAdiscord.js - Imagine an app
Created by Nova Aurelia Knight on 11/15/2023 in #djs-questions
If statement as stated in FAQ failing?
I have the following code, to attempt to restrict a command to only myself, as the wiki states here. What am I doing wrong? Took me a while to figure out how to build everything else but the command is deploying and running, but always running through to the else statement and posting "This command is only for the developer!"
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('reload')
.setDescription('Reloads a command.')
.addStringOption(option =>
option.setName('command')
.setDescription("The command to reload one of Winter's many commands.")
.setRequired(true)),
async execute(interaction) {
if (interaction.user.id === '905600416845267004') {
const commandName = interaction.options.getString('command', true).toLowerCase();
const command = interaction.client.commands.get(commandName);

if (!command) {
return interaction.reply(`There is no command with name \`${commandName}\`!`);
}

delete require.cache[require.resolve(`./${command.data.name}.js`)];

try {
interaction.client.commands.delete(command.data.name);
const newCommand = require(`./${command.data.name}.js`);
interaction.client.commands.set(newCommand.data.name, newCommand);
await interaction.reply(`Command \`${newCommand.data.name}\` was reloaded!`);
} catch (error) {
console.error(error);
await interaction.reply(`There was an error while reloading a command \`${command.data.name}\`:\n\`${error.message}\``);
}
}
else await interaction.reply(`This command is only for the developer!`);
},
};
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('reload')
.setDescription('Reloads a command.')
.addStringOption(option =>
option.setName('command')
.setDescription("The command to reload one of Winter's many commands.")
.setRequired(true)),
async execute(interaction) {
if (interaction.user.id === '905600416845267004') {
const commandName = interaction.options.getString('command', true).toLowerCase();
const command = interaction.client.commands.get(commandName);

if (!command) {
return interaction.reply(`There is no command with name \`${commandName}\`!`);
}

delete require.cache[require.resolve(`./${command.data.name}.js`)];

try {
interaction.client.commands.delete(command.data.name);
const newCommand = require(`./${command.data.name}.js`);
interaction.client.commands.set(newCommand.data.name, newCommand);
await interaction.reply(`Command \`${newCommand.data.name}\` was reloaded!`);
} catch (error) {
console.error(error);
await interaction.reply(`There was an error while reloading a command \`${command.data.name}\`:\n\`${error.message}\``);
}
}
else await interaction.reply(`This command is only for the developer!`);
},
};
7 replies