Code saying the command doesn't exist

client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;

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

if (!command) {
console.error(interaction);
return;
}

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

const errorID = toString(Math.floor(Math.random() * 1000000000));

const errorEmbedServer = new EmbedBuilder()
.setTitle("Critical Error")
.setDescription(`The user ${interaction.user.username} (${interaction.user.id}) has encountered a critical error.`)
.addFields(
{"name": "Command", "value": interaction.commandName, "inline": true},
{"name": "ErrorID", "value": errorID, "inline": true},
{"name": "Error", "value": `\`\`\`${error.stack}\`\`\``}
)
.setColor("RED")

const errorEmbedUser = new EmbedBuilder()
.setTitle("Critical Error")
.setDescription(`Uh Oh, it looks like you've encountered a critical error. Please contact the developers with the errorID of \`${errorID}\``)
.setColor("RED")

logs.createLog(`error-${errorID}`, error.stack); logs.pushLogsToFiles();

interaction.client.channels.fetch(clientData.errorChannel).then(channel => {
channel.send({ embeds: [errorEmbedServer] });
});

if (interaction.replied || interaction.deferred) {
await interaction.followUp({ embeds: [errorEmbedUser], ephemeral: true });
} else {
await interaction.reply({ embeds: [errorEmbedUser], ephemeral: true });
}
}
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;

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

if (!command) {
console.error(interaction);
return;
}

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

const errorID = toString(Math.floor(Math.random() * 1000000000));

const errorEmbedServer = new EmbedBuilder()
.setTitle("Critical Error")
.setDescription(`The user ${interaction.user.username} (${interaction.user.id}) has encountered a critical error.`)
.addFields(
{"name": "Command", "value": interaction.commandName, "inline": true},
{"name": "ErrorID", "value": errorID, "inline": true},
{"name": "Error", "value": `\`\`\`${error.stack}\`\`\``}
)
.setColor("RED")

const errorEmbedUser = new EmbedBuilder()
.setTitle("Critical Error")
.setDescription(`Uh Oh, it looks like you've encountered a critical error. Please contact the developers with the errorID of \`${errorID}\``)
.setColor("RED")

logs.createLog(`error-${errorID}`, error.stack); logs.pushLogsToFiles();

interaction.client.channels.fetch(clientData.errorChannel).then(channel => {
channel.send({ embeds: [errorEmbedServer] });
});

if (interaction.replied || interaction.deferred) {
await interaction.followUp({ embeds: [errorEmbedUser], ephemeral: true });
} else {
await interaction.reply({ embeds: [errorEmbedUser], ephemeral: true });
}
}
});
everytime I execute the command it says: [ERROR] command ping wasn't found even though it was successfully registered. Here's my slash command file:
const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
description: 'Replies with Pong!',
permissions: [],
isHidden: true,

data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
await interaction.reply('Pong!');
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
description: 'Replies with Pong!',
permissions: [],
isHidden: true,

data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
await interaction.reply('Pong!');
},
};
2 Replies
d.js toolkit
d.js toolkit17mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers. - Issue solved? Press the button!
Ethereal <3
Ethereal <3OP17mo ago
And if I try printing the variable command, it returns undefined funny enough when printing our interaction, it has commandName: 'ping', in it wait... i was using a invaild type for my naming scheme im kinda stupid thx tho
Want results from more Discord servers?
Add your server