javascript - 命令不是函数
问题描述
大家下午好
希望这里的人可以提供帮助,很多网络拖网,我无法弄清楚为什么我的应用程序崩溃了,
如果我在已知命令中执行命令,只要我执行不存在的命令,应用程序就会崩溃。
无论我尝试使用 else 语句做什么,应用程序都会崩溃。
任何帮助将不胜感激。
谢谢
// Register our event handlers (defined below):
client.on("message", onMessageHandler);
client.on("connected", onConnectedHandler);
client.on("disconnected", onDisconnectedHandler);
// Connect to Twitch:
client.connect();
// Called every time a message comes in:
function onMessageHandler(target, context, msg, self) {
if (self) {
return;
} // Ignore messages from the bot
// This isn't a command since it has no prefix:
if (msg.substr(0, 1) !== commandPrefix) {
console.log(`[${target} (${context["message-type"]})] ${context.username}: ${msg}`)
return
}
// Split the message into individual words:
const parse = msg.slice(1).split(" ");
// The command name is the first (0th) one:
const commandName = parse[0];
// The rest (if any) are the parameters:
const params = parse.splice(1);
// If the command is known, let's execute it:
if (commandName in knownCommands || knownCommandsMod) {
// Retrieve the function by its name:
const command = knownCommands[commandName] || knownCommandsMod[commandName]
// Then call the command with parameters:
command(target, context, params)
console.log(`* Executed ${commandName} command for ${context.username}`)
} else {
console.log(`* Unknown command ${commandName} from ${context.username}`)
}
}
解决方案
推荐阅读
- c - Cmockery on C 内置函数
- c# - SelectNodes 带来了许多结果
- wordpress - WSL Ubuntu 对使用 WordPress 安装的驱动器文件夹的权限(询问 FTP 凭据或 chmod 错误)
- apache-spark - 如何在 EMR 6.3 中运行的 SparkConf 中设置 spark.sql.legacy.allowUntypedScalaUDF 标志
- python - 用另一个字典的值替换字典的值
- filter - RDP/Citirx WMI 过滤器(如果不在域中)
- kotlin - 从 api 检索数据并放入房间
- html - HTML LANG 属性窃听西里尔字体(用于 Firefox)
- kubernetes - 使用 Kompose 将 docker-compose 转换为 kubernetes
- php - 仅在没有链接产品的 WooCommerce 单品页面上添加价格后缀