简体   繁体   English

如何修复我的帮助命令 (discord.js)

[英]How can I fix my help commands (discord.js)

Currently I am using node.js So I can't require a command and I am unable to find a folder code:目前我正在使用 node.js 所以我不需要命令也找不到文件夹代码:

    module.exports = {
    name: 'cmds',
    description: 'Shows the commands.',
    aliases: 'commands,help',
    cooldown: 1000,
    execute(client, msg, args) {
        const prettyms = require('pretty-ms')
        const author = msg.author
        const authorMember = msg.member
        const user = msg.mentions.users.first()
        const userMember = msg.mentions.members.first()
        const authorOrUser = user || author
        const authorOrUserMember = userMember || authorMember
        const fs = require('fs')
        const { MessageEmbed } = require("discord.js")
        const embed = new MessageEmbed()
        function getCommand(cmd) {
            return client.commands.get(`${cmd}`)
        }
        for (const category of fs.readdirSync(`../commands`)) {
            for (const cmd of fs.readdirSync(`../${category}`)) {
                const command = require(`../${category}/${cmd}`)
                console.log(command.name)
            }
        }
        embed.setAuthor(`Commands : ${client.commands.size}`)
        embed.setDescription("`<> means required, () means optional and | means it is an alias of a command`")
        embed.setFooter(`Made by 3F1VE#2276`)
        embed.setTimestamp(Date.now())
        embed.setTitle(`Commands`)
        embed.setColor('RANDOM')
        msg.reply({ embeds: [embed] })
    }
}

The problem is I cannot find a way to get the commands folder properly.问题是我找不到正确获取命令文件夹的方法。 Here are the files这是文件文件

You would need to set the folder list wherever you fetch yhem on startup or fetch them everything in the command(not recommended)您需要在启动时获取 yhem 的任何位置设置文件夹列表或在命令中获取所有内容(不推荐)

const { readdirSync } = require("fs");
module.exports = (bot) => {
  readdirSync("./commands/").map((dir) => {
    const commands = readdirSync(`./commands/${dir}/`).map((cmd) => {
      let pull = require(`../commands/${dir}/${cmd}`);
      bot.commands.set(pull.name, pull);
      if (pull.aliases) {
        pull.aliases.map((p) => bot.aliases.set(p, pull));
      }
    });
  });
  console.log(`All commands loaded\(Quantity\:${bot.commands.size} \)`)
};

You can change the above provided code with minor changes to fetch the folders in the command itself您可以更改上面提供的代码并稍作更改以在命令本身中获取文件夹

Please remember this is pseudo code and would need changes to fit your use case please don't expect it to work out of thr box请记住这是伪代码,需要更改以适合您的用例请不要指望它可以开箱即用

Apparently I typed in the path wrong.显然我输入了错误的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复我的 discord 机器人(在 discord.js 中)不响应我的命令 - How do I fix my discord bot (in discord.js) not responding to my commands 我的睡眠 function 不适用于某些命令,我该如何解决? (discord.js) - My sleep function not working for certain commands, how do I fix it? (discord.js) Discord.js ban/kick 命令可供所有用户使用。 我怎样才能解决这个问题? - Discord.js ban/kick commands available to all users. How can I fix this? 如何使用 discord.js 将命令部署到所有公会? - How can I deploy commands to all guilds with discord.js? 如何在我的 say 命令代码 discord.js 中修复此错误 - How can I fix this error in my say command code discord.js 有什么办法可以修复我正在创建的 discord 机器人 discord.js - Is there any way i can fix my discord bot, which i`m creating discord.js 无法部署我的斜杠命令 Discord.js - Can't deploy my slash commands Discord.js (DISCORD.JS) 如何修复我的 discord“cmds”命令? - (DISCORD.JS) how do i fix my discord "cmds" command? discord.js - 如何将“尝试我的命令”功能添加到我的机器人? - discord.js - How do i add the "TRY MY COMMANDS" feature to my bot? Discord.js机器人程序需要帮助-如何使我的机器人每6小时自动执行一项任务而不发送命令? - Discord.js bot help needed - how can I make my bot auto do a task every 6 hours without sending it a command?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM