I followed the discord.js slash command guide but it does'nt work. Can someone help me? https://discordjs.guide/creating-your-bot/event-handling.html#individual-event-files
#My slash command bot does'nt work
27 messages · Page 1 of 1 (latest)
• 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.
my code is the same as this one: https://github.com/discordjs/guide/tree/main/code-samples/creating-your-bot/event-handling
No it‘s not. Show your actual code.
If it was it wouldn’t error
Because that example you linked doesn’t have any commands
everything?
How about your index.js or wherever you define your client in
index.js
**const fs = require('node:fs');
const path = require('node:path');
const { Client, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
client.login(token);**
Okay, so you only have code for registering events in there. But you said you had slashcommands? Where are they?
Don’t blindly copy code but actually follow the guide step by step
You‘re missing the part where you actually create client.commands and fill it
...
This one in particular, you probably skipped that or replaced your code when you blindly copy&pasted the index.js from the repo of event handling
never mind... its not helping me.
i read and copy the code at the end the first, and second time.
and i believe there is nothing to setup outside the code.
Read the text too… coding isn’t a game of copy&paste, you also need to understand what you’re doing
no shit
i understood that the first time i posted
people regularly dont help, they send link and say: read, dont ask for code
Then where in your code is the client.commands = new Collection(); part?
Believe it or not, helping is a two-way-street. Show effort and people will show effort to help you too… only show you copy and paste code without understanding and people will not try to help as much indeed
Creating Your Bot: Individual command files