slash command issue

I have command called /ping and its loaded correctly but my bot is not showing/can't it
const commandFolders = fs.readdirSync("./commands");

for (const folder of commandFolders) {
const filePath = path.join("./commands", folder);
const commandFiles = fs
.readdirSync(filePath)
.filter((file) => file.endsWith(".js"));

for (const file of commandFiles) {
try {
let command = await import(`./commands/${folder}/${file}`); // Use dynamic import
command = command.default;

if (command.data && command.execute) {
client.commands.set(command.data.name, command);
} else {
console.log(
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
);
}
} catch (error) {
console.error(`[ERROR] Failed to load command ${filePath}: ${error}`);
}
}
}
const commandFolders = fs.readdirSync("./commands");

for (const folder of commandFolders) {
const filePath = path.join("./commands", folder);
const commandFiles = fs
.readdirSync(filePath)
.filter((file) => file.endsWith(".js"));

for (const file of commandFiles) {
try {
let command = await import(`./commands/${folder}/${file}`); // Use dynamic import
command = command.default;

if (command.data && command.execute) {
client.commands.set(command.data.name, command);
} else {
console.log(
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
);
}
} catch (error) {
console.error(`[ERROR] Failed to load command ${filePath}: ${error}`);
}
}
}
17 Replies
d.js toolkit
d.js toolkit2mo 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
mallusrgreat
mallusrgreat2mo ago
so do you register the commands to discord?
Omar
OmarOP2mo ago
how do i do that?
d.js docs
d.js docs2mo ago
:guide: Creating Your Bot: Registering slash commands read more
Omar
OmarOP2mo ago
now what, i did it and it succeeded and still cant use the command
import { REST, Routes } from 'discord.js';
import fs from 'fs/promises';
import path from 'path';
import dotenv from 'dotenv';

dotenv.config();

const commands = [];

async function getCommands() {
const commandFolders = await fs.readdir('commands');

for (const folder of commandFolders) {
const commandsPath = path.join('commands', folder);
const commandFiles = await fs.readdir(commandsPath);

console.log(`Loading ${commandFiles.length} commands from ${commandsPath}`);

for (const file of commandFiles) {
let command = await import(`./commands/${folder}/${file}`);
command = command.default;

if (command.data && command.execute) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
}

const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN);

(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

await getCommands();

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands }
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();
import { REST, Routes } from 'discord.js';
import fs from 'fs/promises';
import path from 'path';
import dotenv from 'dotenv';

dotenv.config();

const commands = [];

async function getCommands() {
const commandFolders = await fs.readdir('commands');

for (const folder of commandFolders) {
const commandsPath = path.join('commands', folder);
const commandFiles = await fs.readdir(commandsPath);

console.log(`Loading ${commandFiles.length} commands from ${commandsPath}`);

for (const file of commandFiles) {
let command = await import(`./commands/${folder}/${file}`);
command = command.default;

if (command.data && command.execute) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
}

const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN);

(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

await getCommands();

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands }
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();
thats the command
import { SlashCommandBuilder } from "discord.js";

export default {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Replies with Pong!"),

async execute(interaction) {
await interaction.reply("Pong!");
},
};
import { SlashCommandBuilder } from "discord.js";

export default {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Replies with Pong!"),

async execute(interaction) {
await interaction.reply("Pong!");
},
};
treble/luna
treble/luna2mo ago
did you refresh your discord client
Omar
OmarOP2mo ago
yep i did
treble/luna
treble/luna2mo ago
And what isnt working Does the command show up at all
Omar
OmarOP2mo ago
it doesnt
treble/luna
treble/luna2mo ago
Then log to see what you are deploying
Omar
OmarOP2mo ago
Loading 1 commands from commands\utility [ { id: 'id', application_id: 'id', version: '1284912689256202405', default_member_permissions: null, type: 1, name: 'ping', name_localizations: null, description: 'Replies with Pong!', description_localizations: null, dm_permission: true, contexts: null, integration_types: [ 0 ], nsfw: false } ] Successfully reloaded 1 application (/) commands. there is the response i did both :pepehmm:
Omar
OmarOP2mo ago
No description
Omar
OmarOP2mo ago
so i have to require the guild id?
d.js docs
d.js docs2mo ago
:method: SlashCommandBuilder#setIntegrationTypes() @1.9.0 Sets the integration types of this command.
Omar
OmarOP2mo ago
i have both enabled and tried in guild
Omar
OmarOP2mo ago
?
No description
Omar
OmarOP2mo ago
and what about the user install? sorry for bothering you ty
Want results from more Discord servers?
Add your server