我将如何创建一个帮助命令来手动捕获它们?

时间:2020-09-20 08:48:42

标签: discord.js

我正在尝试创建一个帮助命令,当您使用它时,不必手动键入所有命令,该怎么办?就像我执行!help实用程序一样,我将如何获取该实用程序文件夹,然后获取所有命令并将其列出?我一直在尝试fs,但它与您如何获得指挥混淆。有帮助吗?

1 个答案:

答案 0 :(得分:0)

使用fs

使您处在正确的轨道上
const fs = require('fs')

// check if that folder exists
if (!fs.existsSync(`../../commands/${args[0]}`))
 return message.channel.send('That folder does not exist');

// make array of all files within this folder
const files = fs.readdirSync(`../../commands/${args[0]})

for (const file of files) {
  const command = require(`../../commands/${args[0]}/${file}`) // require the file

  // now you can do whatever you want with it!
  console.log(command.name, command.desription)
};