【发布时间】: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”是从哪里来的。
编辑:就我而言,这是一个令人尴尬的错误。我只是有点困惑。一切都清楚了,谢谢。
【问题讨论】:
-
1. stackoverflow.com/q/2802055/3001761 2. “[它]来自哪里”是什么意思?它是函数的参数,例如阅读developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/….
-
Re ^^: 如果
cmd => ...对你来说不是一个函数,那是公平的!见stackoverflow.com/questions/24900875/…
标签: javascript node.js discord.js