Glitch folders discord js

Hey everyone im trying to make a discord bot but i whan to know why i cant make the help.js witch is in a folder work like a command

Hi Anthox, welcome!

What have you tried? Is your help.js file included in your main js using an import or require statement?

Can you post your Glitch project name? :slight_smile:

1 Like

Hey this is the link i hope you can help me

As a general matter you should consider refactoring your message handlers. For the time being however note that you have exposed your secret bot Discord token to the public in the config.json file. You should immediately regenerate that key and hide it in the .env file not the config.

I get the impression that you want to move the code for your help command into the file commands/help.js which is currently empty.

Each of your client responders is a function, for example:

client.on('message', message => { 
 // This is the body of a function with one parameter (message) 
});

You could reorganise the code like this:

const helpResponder = message => {
 // This is the body of a function with one parameter (message) 
}

client.on('message', helpResponder);

Once you have the functions separated out, it is easier to move them to other files.

You can move the definition of your new helpResponder, pcBuildResponder etc to a file. At the end of your help.js file, use module exports:

// help.js

const helpResponder = message => {
 // This is the body of a function with one parameter (message) 
}
module.exports = helpResponder;

Then in your main.js, import and use it:

const helpResponder = require("./commands/help.js");
client.on('message', helpResponder);

More info:

And as tleylan says, move your Discord token to .env and delete the config.json file! Anyone with your token can impersonate your bot.

Hope it helps!

1 Like

My friend im not stupid i have change the token when i post the link

Thanks you very mach :heart:

So we are clear this isn’t about being “stupid”. You could easily have overlooked it but the main point here is (as SteGriff repeated) server secrets should not be stored in a config file. Yourself and others may want to take a moment out and read about it. The arguments for and against the practice are well documented.

Ok my friend thanks you

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.