cant get slash command to handle
Im following this guide (by the way, I can't believe this guide spends so much time writing extra code to build directories of directories of little individual command/event files, what a waste of time and mental load when I'm just trying to learn the command interaction, as well as "bONuS! cOMMaNdS!", jesus)
https://discordjs.guide/creating-your-bot/command-deployment.html#guild-commands
when I run /ping in my server it never comes back. I see the "ready" in my log, but i had an old app interaction URL from a different library's example, but I don't understand what I'm supposed to set it to using discordjs, and the guides dont seem to tell me what to use. I'm assuming this is the problem but don't understand what to do.
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
6 Replies
• 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.// Require the necessary discord.js classes
const { Client, Events, Collection, GatewayIntentBits } = require('discord.js');
const fs = require('node:fs');
const path = require('node:path');
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(
[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.
);
}
}
}
client.once(Events.ClientReady, () => {
console.log('Ready!');
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) 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 });
}
}
});
// Log in to Discord with your client's token
client.login(process.env.BOT_TOKEN);
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Paong!'),
async execute(interaction) {
await interaction.reply('Pong!');
},
};You are missing the actual deploy code
Or where is that
deploy-commands.js isnt it
if I wasnt wrong, you have to copy paste the deplpy-commands.js from the official website, and run node deploy-commands.js in your terminal