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!`);
},
};
3 Replies
d.js toolkit
d.js toolkit13mo 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 staff
Nova Aurelia Knight
Nova Aurelia KnightOP13mo ago
A quick way to make the response ethereal would be nice, too, but wouldn't solve my issue. exact version 14.14.1, no error, I believe I explained the issue and code is above Not sure if this is exactly related to discord.js but if the wiki is incorrect it probably belongs here
duck
duck13mo ago
this is the correct place for this, yes the if statement on its own looks correct, and there aren't really that many moving parts going into it I can see that that id is your id, so the only thing off the top of my head that could cause interaction.user.id to be the wrong id without erroring would be if you had mismatched params, such as if the first param is supposed to be your Client this would result in you actually accessing your bot's id rather than the user who used the command it's also possible that somewhere in your code you accidentally modified the value of the given User object's id, but I'm hoping this is unlikely
Want results from more Discord servers?
Add your server