Slash Command registered but application cannot locate it when called

Trying to update an older bot to use slash commands and I have run into an issue when responding to the client.
bot.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(`[WARNING] No command matching ${interaction.commandName} was found.`);
return;
}

try {
await command.execute(interaction);
} catch (error) {
console.error(error);

if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: "There was an error while executing this command!", ephemeral: true });
} else {
await interaction.reply({ content: "There was an error while executing this command!", ephemeral: true });
}
}
});
bot.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(`[WARNING] No command matching ${interaction.commandName} was found.`);
return;
}

try {
await command.execute(interaction);
} catch (error) {
console.error(error);

if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: "There was an error while executing this command!", ephemeral: true });
} else {
await interaction.reply({ content: "There was an error while executing this command!", ephemeral: true });
}
}
});
I am trying to make a simple /ping command but I get
[WARNING] No command matching ping was found.
[WARNING] No command matching ping was found.
in my logs and "The application did not respond" on Discord
No description
7 Replies
d.js toolkit
d.js toolkit5mo 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
monbrey
monbrey5mo ago
That suggests you havent loaded it/anything into client.commands
24Kings
24Kings5mo ago
for (const file of commandFiles) {
const command = require(file);

if ("data" in command && "execute" in command) {
console.info(`[INFO] Loaded command: ${command.data.name}`);
commands.push(command.data.toJSON());
} else {
console.warn(`[WARNING] The command at ${file} is missing a required "data" or "execute" property.`);
}
}

const rest = new REST({ version: "10" }).setToken(token);

// Load commands
(async () => {
try {
console.info(`[INFO] Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(bot.config.clientId, bot.config.guildId),
{ body: commands },
);

console.info(`[INFO] Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
for (const file of commandFiles) {
const command = require(file);

if ("data" in command && "execute" in command) {
console.info(`[INFO] Loaded command: ${command.data.name}`);
commands.push(command.data.toJSON());
} else {
console.warn(`[WARNING] The command at ${file} is missing a required "data" or "execute" property.`);
}
}

const rest = new REST({ version: "10" }).setToken(token);

// Load commands
(async () => {
try {
console.info(`[INFO] Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(bot.config.clientId, bot.config.guildId),
{ body: commands },
);

console.info(`[INFO] Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
it seems to locate them ok? Is there any other way I can tell
No description
monbrey
monbrey5mo ago
This doesnt put them in client.commands, this is an entirely separate script for deploying them
24Kings
24Kings5mo ago
oh I see what you mean
d.js docs
d.js docs5mo ago
guide Creating Your Bot: Command handling - Loading command files read more
24Kings
24Kings5mo ago
cool cool, thx I got confused on that part because it looks very similar to deploying them Kek read one too many guides that show you code and then immediately change it on the next slide working now <:PI_aquathumbsup:697627878287867904>
Want results from more Discord servers?
Add your server
More Posts
Error [Object object]In my bot discord i have a defaultrole system, he add the role when a guy join but i add a reason anDiscordAPIError[50013]: Missing PermissionsI have a timeout command my bot has all the permissions it needs so I dont know why im getting this Slash command working but still replying with "The application did not respond"the command works but before its sent it responds with "The application did not respond". ```js coHi i am currently trying to fetch json data from an api using slash commands but it keeps erroring```js const { EmbedBuilder, PermissionsBitField } = require("discord.js"); const { SlashCommandBuildRecommendations for good boilerplate/template projectsHi! New to Discord.js, _very_ familiar with JavaScript/TypeScript. I was hoping to write a Discord bCollection problemIs there any easy way to modify an array that is placed as a value in an Collection object?hey iam builduin a ticket system for my bot with slash command and deploy command buti hav an errorit works fine and it shows the slash command in discord but when i execute it it says this error Erwhy i am getting this and how to fix ?```0|sharded-client | (3:08:07 PM) - [WARN] - ----- Unhandled Rejection ----- 0|sharded-client | (Set Path to custom ffmpeg binaryHello, we're currently encountering issues with the static-ffmpeg module in our Docker container, ocDynamically adding buttons component to interactionGood day were trying to add buttons to a interaction reply Create buttons dynamically - then add th