MauL08 / CSBot

Discord Bot using discord.js library
1 stars 2 forks source link

Don't use so many message listeners #3

Closed Murky-MoMo closed 3 years ago

Murky-MoMo commented 3 years ago
bot.on("message", list);

// Jadwal Command
bot.on("message", jadwal);

// Ping Command
bot.on("message", ping);

// Search Command
bot.on("message", search);

// Audio Command
bot.on("message", audio);

// Covid Command
bot.on("message", covid);

all of the if cases can be inside a single message event listener

bot.on("message" message=> {
     if (command == "jadwal")....
     if (command == "search")....
})

not only is the code inefficient but so adding so many listeners will lead you to get a Memory leak error for more on command handling, i suggest you check out the official guide https://discordjs.guide/command-handling/#individual-command-files

MauL08 commented 3 years ago

OK, I will fix that. Thank you for your suggestion :)