#My slash command bot does'nt work

27 messages · Page 1 of 1 (latest)

thin sorrel
analog finch
#

• 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.

thin sorrel
solid coral
#

If it was it wouldn’t error

#

Because that example you linked doesn’t have any commands

thin sorrel
#

everything?

solid coral
#

How about your index.js or wherever you define your client in

thin sorrel
#

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);**

solid coral
#

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

thin sorrel
solid coral
#

You‘re missing the part where you actually create client.commands and fill it

red dockBOT
#

guide Creating Your Bot: Individual command files
read more

thin sorrel
#

...

red dockBOT
solid coral
#

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

thin sorrel
#

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.

solid coral
#

Read the text too… coding isn’t a game of copy&paste, you also need to understand what you’re doing

thin sorrel
#

i understood that the first time i posted

#

people regularly dont help, they send link and say: read, dont ask for code

solid coral
#

Then where in your code is the client.commands = new Collection(); part?

solid coral