javascript - 我的不和谐机器人忽略了其中包含大写字母的命令
问题描述
所以我正在尝试组装一个机器人,我发现无论出于何种原因,它都不会响应任何包含大写字母的命令。我的意思是它已经定义了包含大写字母的命令,但机器人实际上不会运行包含大写字母的命令中的代码。我在下面输入的开关/案例中定义了我的命令,它使用从主文件传递给命令文件的对象的属性。
switch (command.call) {
case 'ping':
message.reply(`Pong! This message had a latency of ${latency}ms.`);
console.log(`Received message $ping, responded with latency of ${latency}ms.`);
break;
case 'help':
message.reply('Current commands available:\n \`$ping\`: Get the latency of the bot.\n \`$help\`: Show this message.\n \`$setPrefix\` \`[arg]\`: Set the prefix to a given string, \`[arg]\`');
console.log(`Received message $help, responded with latency of ${latency}ms.`);
break;
case 'setPrefix':
message.reply(`Set the new prefix to ${config.prefix}`);
console.log(`Received message $setPrefix, responded with latency of ${latency}ms.`);
break;
case 'Test':
message.reply('I got your message!');
console.log(`Received message $test, responded with latency of ${latency}ms.`);
break;
}
}
所以命令ping
和工作正常,但是当我尝试调用或help
时机器人没有做任何事情。setPrefix
Test
这是我将命令传递给定义命令的文件的代码:
commandBody = message.content.slice(config.prefix.length), //Get the body of the command
args = commandBody.split(' '), //Get the command arguments
call = args.shift().toLowerCase() //Get the command
const command = {
commandBody: commandBody,
args: args,
call: call
}
commands(command, message); //Call the given command from commands.js
调用 commands() 的最后一行引用了定义机器人命令的文件
解决方案
添加到您的代码.toLowerCase()
推荐阅读
- android - 如何使用 Retrofit 和 Kotlin 协程下载 PDF 文件?
- micronaut - 多个获取请求参数@PathVariable 和@RequestAttribute 与Micronaut?
- r - 如何在ggplot2中创建具有总频率和百分比的堆积条形图
- python - 如何在给定的参数位置柯里化函数
- django - DRF - 如何正确更新外键
- python - “权限被拒绝”试图在 Windows 10 上运行 Python
- session - 会话到期时如何通知我?
- ionic-framework - Ionic + Capacitor - iOS 上的 PWA 移动摄像头访问 - 在 Safari 中工作 - 但不是从主屏幕图标
- javascript - 类型错误:props.theTodos.map 不是函数
- php - laravel-excel 未定义索引:$