Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 动态信息命令通过命令循环查找特定命令_Javascript_Discord_Discord.js_Bots - Fatal编程技术网

Javascript 动态信息命令通过命令循环查找特定命令

Javascript 动态信息命令通过命令循环查找特定命令,javascript,discord,discord.js,bots,Javascript,Discord,Discord.js,Bots,因此,我想在我的命令处理程序的帮助下生成一个动态信息命令,因此基本上它需要循环执行该命令,检查该命令是否等于args[0],然后显示该命令的信息,目前我在检查该命令是否等于用户编写的命令时遇到问题 我的代码 const Discord = require('discord.js') const loadCommands = require('./load-commands') module.exports = { commands: 'info', minArgs: 1,

因此,我想在我的命令处理程序的帮助下生成一个动态信息命令,因此基本上它需要循环执行该命令,检查该命令是否等于
args[0]
,然后显示该命令的信息,目前我在检查该命令是否等于用户编写的命令时遇到问题

我的代码

const Discord = require('discord.js')
const loadCommands = require('./load-commands')

module.exports = {
    commands: 'info',
    minArgs: 1,
    maxArgs: 1,
    info: 'displays info about commands'
    callback: async (message, args, text, client) => {
        let reply = ''
        const commands = loadCommands()
        
        for (const command of commands) {
          // Check for permissions
          let permissions = command.permission
        
          if (permissions) {
            let hasPermission = true
            if (typeof permissions === 'string') {
              permissions = [permissions]
            }
        
            for (const permission of permissions) {
              if (!message.member.hasPermission(permission)) {
                hasPermission = false
                break
              }
            }
        
            if (!hasPermission) {
              continue
            }
          }
                //Format the text
                let alias = args[0]
                const mainCommand = typeof command.commands === 'string' 
                ? command.commands
                : command.commands[0]
                const { info } = command
                reply += info
            }
            message.channel.send(reply)
            },
        }

我需要它来检查用户编写的命令(=info)是否存在,如果存在,则显示该命令的信息,如果您需要任何其他代码,如我的命令处理程序或“load commands.js”文件,请告诉我,我将向您展示,我试图找到一些方法来做这件事,但找不到任何有效的方法。

下面是如何使用地图来做这件事。我还解析该命令并返回一个命令对象

const commands=newmap();
命令[“打印”]=(参数)=>{
console.log(…args)
}
常量前缀=“!”;
函数parseCommand(内容){
const[command,…args]=content.trim().split(“”);
返回{
指挥部,
args
}
}
const userCommand=“!打印Hello测试1”;
if(userCommand.trim().startsWith(前缀)){
const request=parseCommand(“打印Hello测试1”);
命令[request.command](request.args);
}否则{
log(“消息没有bot前缀”);
}