Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Command handler is not recieving commands #98

Closed
WaterBlueNewWorld opened this issue Apr 2, 2020 · 2 comments
Closed

Command handler is not recieving commands #98

WaterBlueNewWorld opened this issue Apr 2, 2020 · 2 comments

Comments

@WaterBlueNewWorld
Copy link

To be honest i don't know if the problem is with the command handler, but i tried to make one using the guide, but when i try to use the command "+ping" i don't get a response

This is the code for the index.js

const fs = require('fs');
const Discord = require('discord.js');
const Enmap = require('enmap');
const client = new Discord.Client();
const config = require('./config.json');

client.config = config;

fs.readdir("./events/", (err, files) =>{
  if(err)return console.error(err);
  files.forEach(file => {
    const event = require(`./events/${file}`);
    let eventName = file.split(".")[0];
    console.log(`Loading: ${eventName}`);
    client.on(eventName, event.bind(null, client));
  });
});

client.commands = new Enmap();

fs.readdir("./commands/", (err, files)=>{
  if (err) return console.error(err);
  files.forEach(file=>{
    if(!file.endsWith(".js")) return;
    let props = require(`./commands/${file}`);
    let commandName = file.split(".")[0];
    console.log(`Loading ${commandName}`);
    client.commands.set(commandName, props);
  });
});

This is the code for ping.js

exports.run = (client,message,args)=>{
    message.channel.send("Ping").catch(console.error);
};

This is the code for the messages.js

module.exports = (client, message) => {
   
    if (message.author.bot)return;
    
    if(message.content.indexOf(client.config.prefix)!==0)return;

    const args = message.content.slice(client.config.prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

    const cmd = client.commands.get(command);
    console.log("yes");
    if(!cmd) return;

    cmd.run(client,message,args);
    
};
@eslachance
Copy link
Contributor

Why does it feel like you removed every single space you could in this code? You know that can break things, right? Please undo that crap and try again.

@WaterBlueNewWorld
Copy link
Author

Why does it feel like you removed every single space you could in this code? You know that can break things, right? Please undo that crap and try again.

In the end the problem was that the event file was called "messages.js", i changed its name to "message.js" and everything started to work as intended

Still thanks for the reply, and sorry for bothering

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants