【问题标题】:Confused on where "cmd" originates from? [closed]对“cmd”的来源感到困惑? [关闭]
【发布时间】:2021-03-19 23:48:39
【问题描述】:

刚刚完成了 codeacademy 的 Learn JavaScript,目前正在学习 Discord.js 指南。学习如何指挥处理,遇到了一些我不太明白的事情。

const fs = require('fs');

module.exports = {
    name: 'reload',
    description: 'Reloads a command',
    execute(message, args) {
        const commandName = args[0].toLowerCase();
        const command = message.client.commands.get(commandName)
            || message.client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));

        if (!command) return message.channel.send(`There is no command with name or alias \`${commandName}\`, ${message.author}!`);
    },
};

这些代码行:

message.client.commands.get(commandName)
            || message.client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));

1.我对什么“||”感到困惑意思是(是'或',如果是我不明白这个语法)

2。我不知道“cmd”是从哪里来的。

编辑:就我而言,这是一个令人尴尬的错误。我只是有点困惑。一切都清楚了,谢谢。

【问题讨论】:

标签: javascript node.js discord.js


【解决方案1】:
  1. 是的,它是“或”运算符。在这种情况下,如果 message.client.commands.get(commandName) 评估为 true,它将将该值分配给“command”。否则,它会将另一个值赋给 ||

  2. 'find' 迭代数组中的值,直到结果为真。 'cmd' 是当前迭代的值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 2016-09-04
    • 2012-05-03
    • 1970-01-01
    • 2018-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多