Ask coding questions

← Back to all posts
How do I make / commands node.js
Jasonkingtou

I dont know how to make / commands so i need help

Voters
Jasonkingtou
Comments
hotnewtop
mumuji1723

Actually, it can be easier. What you do is make a folder with all commands called "commands", then create
a file called deploy-commands.js Now, to create a command, in your "commands" folder, create a file called ping.js type the following:
module.exports = function(){
msg.reply("Pong!")
}
Then, in your deploy commands, you type
const ping = require("./commands/ping.js")
clist = {ping}
module.exports = async function(msg){
let tokens = msg.toString().split(" ");
let command = tokens.shift();
if (command.charAt(0) == '!') {
command = command.substring(1);
clist[command](msg, tokens);
}
};
Finally, index.js:
//depencencies,on ready, etc
const commhand = require("./deploy-commands.js")
client.on('message',commhand)
//others
This is assuming it is blank, new file.
It also appears that you are missing function(msg,args) in your files.