My Command Handler Doesn’t work

My Handler

const Discord = require(“discord.js”);

2

const fs = require(“fs”);

3

const client = new Discord.Client();

4

5

fs.readdir("./events/", (err, files) => {

6

if (err) return console.error(err);

7

files.forEach(file => {

8

const event = require(./events/${file});

9

let eventName = file.split(".")[0];

10

client.on(eventName, event.bind(null, client));

11

});

12

});

13

14

client.commands = new Discord.Collection();

15

16

fs.readdir("./commands/", (err, files) => {

17

if (err) return console.error(err);

18

files.forEach(file => {

19

if (!file.endsWith(".js")) return;

20

let props = require(./commands/${file});

21

let commandName = file.split(".")[0];

22

console.log(Attempting to load command ${commandName});

23

client.commands.set(commandName, props);

24

});

25

});

26

27

client.login(process.env.BOT_TOKEN);

28

My events on message code

module.exports = (client, message) => {

2

// Ignore all bots

3

if (message.author.bot) return;

4

5

const prefix = “fl”

6

7

// Ignore messages not starting with the prefix (in config.json)

8

if (message.content.indexOf(prefix) !== 0) return;

9

10

// Our standard argument/command name definition.

11

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

12

const command = args.shift().toLowerCase();

13

14

// Grab the command data from the client.commands - Collection

15

const cmd = client.commands.get(command);

16

17

// If that command doesn’t exist, silently exit and do nothing

18

if (!cmd) return;

19

20

// Run the command

21

cmd.run(client, message, args);

22

};

23

My Test Command Code

exports.run = (client, message, args) => {
2
message.channel.send(“Test Completed!”).catch(console.error);
3
}

Basically whenever I use the command fltest nothing happens

IMG_0487

@EpicFlameDragon, are you getting any errors in the logs?

2 Likes

No everything is fine

@EpicFlameDragon, can you format the code or provide a link to the project, because the code is a bit hard to read.

Join link removed by Glitch Support. To keep your project safe, please send project invites by private message only.

@EpicFlameDragon, as you’ve DMed me, the command handler worked when you moved the files to index.js.