v2.5.2
Giriş yap

npm discord.js modülü için fs ile command handler yapmak

mrturk
766 defa görüntülendi ve 1 kişi tarafından değerlendirildi

Sorunum

discord.js için yaptığım handlerdaki hatayı bulamadım, herşeyi eksiksiz yaptığımı biliyorum ama bir türlü cevap vermiyor bot

Modüller
Handler

const folders = fs.readdirSync("./commands/")

for (const files of folders) {
const folder = fs.readdirSync(`./commands/${files}/`).filter(file => file.endsWith(".js"))

for (const commands of folder) {
  const command = require(`./commands/${files}/${commands}`)
  console.log(`./commands/${files}/${commands}`)
    bot.on('message',message => {
        const args = message.content.slice(config.prefix.length).trim().split(/ +/);
        if(message.content !== `${config.prefix}${command.name}` || `${config.prefix}${command.aliases.join(' || ')}`) return;
        require(`./commands/${files}/${commands}`)(bot,message,args)
        if(message.author.bot) return;
        command.code
    })
  }
}
Örnek kullanım

Dosya yolu

./commands/user/ping.js
module.exports = {
    name: "ping",
    aliases: [],
    code: async (bot, message, args) => {
      message.channel.send('pong')
    }
  }

Önemli not

Cevap olarak hazır handler yazmayın , 'bot' tanımlanmıştır
mrdark
930 gün önce
const folders = fs.readdirSync("./commands/");
const commands = new Map();
for (const files of folders) {
const folder = fs.readdirSync(`./commands/${files}/`).filter(file => file.endsWith(".js");

for (const commands of folder) {
  const command = require(`./commands/${files}/${commands}`);
  
   commands.set(commands.name, commands)
  };
};

 bot.on("message", message => {
            if (message.author.bot) return;
            if (message.content.indexOf(prefix) !== 0) return;
            const args = message.content.slice(prefix.length).trim().split(/ +/g);
            const command = args.shift().toLowerCase();
            const cmd = commands.get(command);
            if (!cmd) return;
            cmd.code(bot, message, args);
        })